*Partisanship, Electoral Autocracy, and Citizen Perceptions of Party System Polarization

*Please note that all micro- and macro-level variables needed for replication are already included in the dataset on the Political Behavior Dataverse website (see "CSES 1-5 subjective party system polarization dataset.dta"). This dataset combines the CSES Integrated 1-4 Module Dataset (IMD) ("cses_imd", December 08, 2020 version) and the CSES Module 5 data ("cses5", May 14, 2020 version) - both available for download on https://cses.org.

*The information below indicates how to re-create the variables for  the empirical results reported in the paper. Further details about the sample and variable coding are available in the Online Appendix. 


*CSES module
gen module=.
replace module=1 if IMD1008_MOD_1==1
replace module=2 if IMD1008_MOD_2==1
replace module=3 if IMD1008_MOD_3==1
replace module=4 if IMD1008_MOD_4==1
replace module=5 if IMD1001!="CSES-IMD"
label var module "CSES module, 1-5"

replace IMD1004=E1004 if module==5

*r_IP - Perceived party system polarization using CSES1-4 data

*Party vote shares(lower house): recoding missing values 
replace IMD5001_A=. if IMD5001_A>100
replace IMD5001_B=. if IMD5001_B>100
replace IMD5001_C=. if IMD5001_C>100
replace IMD5001_D=. if IMD5001_D>100
replace IMD5001_E=. if IMD5001_E>100
replace IMD5001_F=. if IMD5001_F>100
replace IMD5001_G=. if IMD5001_G>100
replace IMD5001_H=. if IMD5001_H>100
replace IMD5001_I=. if IMD5001_I>100

*Corrected vote shares for selected countries 
*CZE_2002
replace IMD5001_A=30.2 if IMD1004=="CZE_2002"
replace IMD5001_B=24.47 if IMD1004=="CZE_2002"
replace IMD5001_C=18.51 if IMD1004=="CZE_2002"
replace IMD5001_D=14.27 if IMD1004=="CZE_2002"
replace IMD5001_E=. if IMD1004=="CZE_2002"

*HUN_2002
replace IMD5001_A=42.05 if IMD1004=="HUN_2002"
replace IMD5001_B=41.07 if IMD1004=="HUN_2002"
replace IMD5001_C=5.57 if IMD1004=="HUN_2002"
replace IMD5001_D=4.37 if IMD1004=="HUN_2002"
replace IMD5001_E=3.9 if IMD1004=="HUN_2002"
replace IMD5001_F=. if IMD1004=="HUN_2002"
replace IMD5001_G=. if IMD1004=="HUN_2002"
replace IMD5001_H=. if IMD1004=="HUN_2002"
replace IMD5001_I=. if IMD1004=="HUN_2002"

*MEX_2006
replace IMD5001_A=34.2 if IMD1004=="MEX_2006"
replace IMD5001_B=29.7 if IMD1004=="MEX_2006"
replace IMD5001_C=28.9 if IMD1004=="MEX_2006"
replace IMD5001_D=. if IMD1004=="MEX_2006"
replace IMD5001_E=. if IMD1004=="MEX_2006"
replace IMD5001_F=. if IMD1004=="MEX_2006"
replace IMD5001_G=4.7 if IMD1004=="MEX_2006"
replace IMD5001_H=2.1 if IMD1004=="MEX_2006"
replace IMD5001_I=. if IMD1004=="MEX_2006"

*POL_2001
replace IMD5001_A=41.04 if IMD1004=="POL_2001"
replace IMD5001_B=12.68 if IMD1004=="POL_2001"
replace IMD5001_C=10.2 if IMD1004=="POL_2001"
replace IMD5001_D=9.5 if IMD1004=="POL_2001"
replace IMD5001_E=8.98 if IMD1004=="POL_2001"
replace IMD5001_F=7.87 if IMD1004=="POL_2001"
replace IMD5001_G=5.6 if IMD1004=="POL_2001"
replace IMD5001_H=3.1 if IMD1004=="POL_2001"
replace IMD5001_I=. if IMD1004=="POL_2001"

*ROU_2004
replace IMD5001_A=36.8 if IMD1004=="ROU_2004"
replace IMD5001_B=31.48 if IMD1004=="ROU_2004"
replace IMD5001_C=. if IMD1004=="ROU_2004"
replace IMD5001_D=12.99 if IMD1004=="ROU_2004"
replace IMD5001_E=6.2 if IMD1004=="ROU_2004"
replace IMD5001_F=. if IMD1004=="ROU_2004"
replace IMD5001_G=. if IMD1004=="ROU_2004"
replace IMD5001_H=1.86 if IMD1004=="ROU_2004"
replace IMD5001_I=. if IMD1004=="ROU_2004"

*DEU12002
replace IMD5001_G=.6 if IMD1004=="DEU12002"
replace IMD5001_H=.8 if IMD1004=="DEU12002"

*DEU22002
replace IMD5001_G=.6 if IMD1004=="DEU22002"
replace IMD5001_H=.8 if IMD1004=="DEU22002"

*DEU_2005
replace IMD5001_G=1.6 if IMD1004=="DEU_2005"

*ESP_2008
replace IMD5001_A=43.87 if IMD1004=="ESP_2008"
replace IMD5001_B=39.94 if IMD1004=="ESP_2008"
replace IMD5001_C=3.03 if IMD1004=="ESP_2008"
replace IMD5001_D=1.19 if IMD1004=="ESP_2008"
replace IMD5001_E=1.16 if IMD1004=="ESP_2008"
replace IMD5001_F=3.77 if IMD1004=="ESP_2008"
replace IMD5001_G=.83 if IMD1004=="ESP_2008"
replace IMD5001_H=.68 if IMD1004=="ESP_2008"
replace IMD5001_I=1.19 if IMD1004=="ESP_2008"

*GBR_2015
replace IMD5001_A=36.8 if IMD1004=="GBR_2015"
replace IMD5001_B=30.4 if IMD1004=="GBR_2015"
replace IMD5001_C=12.6 if IMD1004=="GBR_2015"
replace IMD5001_D=7.9 if IMD1004=="GBR_2015"
replace IMD5001_E=4.7 if IMD1004=="GBR_2015"
replace IMD5001_F=3.8 if IMD1004=="GBR_2015"
replace IMD5001_G=.6 if IMD1004=="GBR_2015"
replace IMD5001_H=. if IMD1004=="GBR_2015"
replace IMD5001_I=. if IMD1004=="GBR_2015"

*KOR_2004
replace IMD5001_F=.6 if IMD1004=="KOR_2004"

*NLD_1998
replace IMD5001_G=2 if IMD1004=="NLD_1998"

*ROU_1996
replace IMD5001_G=1.6 if IMD1004=="ROU_1996"

*SVN_1996
replace IMD5001_G=3.22 if IMD1004=="SVN_1996"

*SWE_2006
replace IMD5001_I=.68 if IMD1004=="SWE_2006"

*UKR_1998
replace IMD5001_G=4 if IMD1004=="UKR_1998"


*R's perception of pty LR positions: recoding missing values 
replace IMD3007_A=. if IMD3007_A>10
replace IMD3007_B=. if IMD3007_B>10
replace IMD3007_C=. if IMD3007_C>10
replace IMD3007_D=. if IMD3007_D>10
replace IMD3007_E=. if IMD3007_E>10
replace IMD3007_F=. if IMD3007_F>10
replace IMD3007_G=. if IMD3007_G>10
replace IMD3007_H=. if IMD3007_H>10
replace IMD3007_I=. if IMD3007_I>10

gen v_A=IMD5001_A
gen v_B=IMD5001_B
gen v_C=IMD5001_C
gen v_D=IMD5001_D
gen v_E=IMD5001_E
gen v_F=IMD5001_F
gen v_G=IMD5001_G
gen v_H=IMD5001_H
gen v_I=IMD5001_I

replace v_A=. if IMD3007_A==.
replace v_B=. if IMD3007_B==.
replace v_C=. if IMD3007_C==.
replace v_D=. if IMD3007_D==.
replace v_E=. if IMD3007_E==.
replace v_F=. if IMD3007_F==.
replace v_G=. if IMD3007_G==.
replace v_H=. if IMD3007_H==.
replace v_I=. if IMD3007_I==.


egen SPV=rowtotal (v_A v_B v_C v_D v_E v_F v_G v_H v_I)
label var SPV "Sum of all party vote shares in a country-election"

*(R's perception of pty LR position * pty vote share)/SPV
gen wRiVi_A=(IMD3007_A*v_A)/SPV
gen wRiVi_B=(IMD3007_B*v_B)/SPV
gen wRiVi_C=(IMD3007_C*v_C)/SPV
gen wRiVi_D=(IMD3007_D*v_D)/SPV
gen wRiVi_E=(IMD3007_E*v_E)/SPV
gen wRiVi_F=(IMD3007_F*v_F)/SPV
gen wRiVi_G=(IMD3007_G*v_G)/SPV
gen wRiVi_H=(IMD3007_H*v_H)/SPV
gen wRiVi_I=(IMD3007_I*v_I)/SPV

*pty system average LR position (based on respondents)
egen Rm=rowtotal (wRiVi_A wRiVi_B wRiVi_C wRiVi_D wRiVi_E wRiVi_F wRiVi_G wRiVi_H wRiVi_I)
label var Rm "R's based Party system average LR position"

*(R's party placement - Rm)/5
gen RiRm_A=(IMD3007_A - Rm)/5
gen RiRm_B=(IMD3007_B - Rm)/5
gen RiRm_C=(IMD3007_C - Rm)/5
gen RiRm_D=(IMD3007_D - Rm)/5
gen RiRm_E=(IMD3007_E - Rm)/5
gen RiRm_F=(IMD3007_F - Rm)/5
gen RiRm_G=(IMD3007_G - Rm)/5
gen RiRm_H=(IMD3007_H - Rm)/5
gen RiRm_I=(IMD3007_I - Rm)/5

*Square RiRm * Vote%
gen Xv_A=(RiRm_A*RiRm_A)*IMD5001_A
gen Xv_B=(RiRm_B*RiRm_B)*IMD5001_B
gen Xv_C=(RiRm_C*RiRm_C)*IMD5001_C
gen Xv_D=(RiRm_D*RiRm_D)*IMD5001_D
gen Xv_E=(RiRm_E*RiRm_E)*IMD5001_E
gen Xv_F=(RiRm_F*RiRm_F)*IMD5001_F
gen Xv_G=(RiRm_G*RiRm_G)*IMD5001_G
gen Xv_H=(RiRm_H*RiRm_H)*IMD5001_H
gen Xv_I=(RiRm_I*RiRm_I)*IMD5001_I

egen P=rowtotal (Xv_A Xv_B Xv_C Xv_D Xv_E Xv_F Xv_G Xv_H Xv_I)

*Square root of P
gen r_IP14=sqrt(P)
label var r_IP14 "R's ideological (LR) pty system polarization, CSES 1-4"

*e_IP - Party system polarization based on expert pty LR placements, CSES1-4 data
*recoding missing values
replace IMD5012_A=. if IMD5012_A>10
replace IMD5012_B=. if IMD5012_B>10
replace IMD5012_C=. if IMD5012_C>10
replace IMD5012_D=. if IMD5012_D>10
replace IMD5012_E=. if IMD5012_E>10
replace IMD5012_F=. if IMD5012_F>10
replace IMD5012_G=. if IMD5012_G>10
replace IMD5012_H=. if IMD5012_H>10
replace IMD5012_I=. if IMD5012_I>10

gen ev_A=IMD5001_A
gen ev_B=IMD5001_B
gen ev_C=IMD5001_C
gen ev_D=IMD5001_D
gen ev_E=IMD5001_E
gen ev_F=IMD5001_F
gen ev_G=IMD5001_G
gen ev_H=IMD5001_H
gen ev_I=IMD5001_I

replace ev_A=. if IMD5012_A==.
replace ev_B=. if IMD5012_B==.
replace ev_C=. if IMD5012_C==.
replace ev_D=. if IMD5012_D==.
replace ev_E=. if IMD5012_E==.
replace ev_F=. if IMD5012_F==.
replace ev_G=. if IMD5012_G==.
replace ev_H=. if IMD5012_H==.
replace ev_I=. if IMD5012_I==.

egen eSPV=rowtotal (ev_A ev_B ev_C ev_D ev_E ev_F ev_G ev_H ev_I)
label var eSPV "Sum of all party vote shares in a country-election"

*Expert party LR placement * pty vote share/total party vote %
gen weRiVi_A=(IMD5012_A*ev_A)/eSPV
gen weRiVi_B=(IMD5012_B*ev_B)/eSPV
gen weRiVi_C=(IMD5012_C*ev_C)/eSPV
gen weRiVi_D=(IMD5012_D*ev_D)/eSPV
gen weRiVi_E=(IMD5012_E*ev_E)/eSPV
gen weRiVi_F=(IMD5012_F*ev_F)/eSPV
gen weRiVi_G=(IMD5012_G*ev_G)/eSPV
gen weRiVi_H=(IMD5012_H*ev_H)/eSPV
gen weRiVi_I=(IMD5012_I*ev_I)/eSPV


*pty system average LR position (based on experts)
egen eRm=rowtotal (weRiVi_A weRiVi_B weRiVi_C weRiVi_D weRiVi_E weRiVi_F weRiVi_G weRiVi_H weRiVi_I)
label var eRm "Expert-based party system average LR position"

*(Expert party placement - eRm)/5
gen eRiRm_A=(IMD5012_A - eRm)/5
gen eRiRm_B=(IMD5012_B - eRm)/5
gen eRiRm_C=(IMD5012_C - eRm)/5
gen eRiRm_D=(IMD5012_D - eRm)/5
gen eRiRm_E=(IMD5012_E - eRm)/5
gen eRiRm_F=(IMD5012_F - eRm)/5
gen eRiRm_G=(IMD5012_G - eRm)/5
gen eRiRm_H=(IMD5012_H - eRm)/5
gen eRiRm_I=(IMD5012_I - eRm)/5

*Square eRiRm * Vote%
gen eXv_A=(eRiRm_A*eRiRm_A)*IMD5001_A
gen eXv_B=(eRiRm_B*eRiRm_B)*IMD5001_B
gen eXv_C=(eRiRm_C*eRiRm_C)*IMD5001_C
gen eXv_D=(eRiRm_D*eRiRm_D)*IMD5001_D
gen eXv_E=(eRiRm_E*eRiRm_E)*IMD5001_E
gen eXv_F=(eRiRm_F*eRiRm_F)*IMD5001_F
gen eXv_G=(eRiRm_G*eRiRm_G)*IMD5001_G
gen eXv_H=(eRiRm_H*eRiRm_H)*IMD5001_H
gen eXv_I=(eRiRm_I*eRiRm_I)*IMD5001_I


egen eP=rowtotal (eXv_A eXv_B eXv_C eXv_D eXv_E eXv_F eXv_G eXv_H eXv_I)

gen e_IP14=sqrt(eP)
label var e_IP14 "Expert-based ideological (LR) pty system polarization"

drop Xv_A Xv_B Xv_C Xv_D Xv_E Xv_F Xv_G Xv_H Xv_I
drop RiRm_A RiRm_B RiRm_C RiRm_D RiRm_E RiRm_F RiRm_G RiRm_H RiRm_I
drop wRiVi_A wRiVi_B wRiVi_C wRiVi_D wRiVi_E wRiVi_F wRiVi_G wRiVi_H wRiVi_I

drop eXv_A eXv_B eXv_C eXv_D eXv_E eXv_F eXv_G eXv_H eXv_I
drop eRiRm_A eRiRm_B eRiRm_C eRiRm_D eRiRm_E eRiRm_F eRiRm_G eRiRm_H eRiRm_I
drop weRiVi_A weRiVi_B weRiVi_C weRiVi_D weRiVi_E weRiVi_F weRiVi_G weRiVi_H weRiVi_I
drop SPV eSPV Rm eRm P eP
drop ev_A ev_B ev_C ev_D ev_E ev_F ev_G ev_H ev_I
drop v_A v_B v_C v_D v_E v_F v_G v_H v_I


*r_IP - Perceived party system polarization using the CSES5 data

*Party vote shares(lower house): recoding missing values 
replace E5001_A=. if E5001_A>100
replace E5001_B=. if E5001_B>100
replace E5001_C=. if E5001_C>100
replace E5001_D=. if E5001_D>100
replace E5001_E=. if E5001_E>100
replace E5001_F=. if E5001_F>100
replace E5001_G=. if E5001_G>100
replace E5001_H=. if E5001_H>100
replace E5001_I=. if E5001_I>100

*Corrected vote shares for selected countries 
*replace E5001_A= if E1004==""

*R's perception of pty left-right positions: recoding missing values 
replace E3019_A=. if E3019_A>10
replace E3019_B=. if E3019_B>10
replace E3019_C=. if E3019_C>10
replace E3019_D=. if E3019_D>10
replace E3019_E=. if E3019_E>10
replace E3019_F=. if E3019_F>10
replace E3019_G=. if E3019_G>10
replace E3019_H=. if E3019_H>10
replace E3019_I=. if E3019_I>10

gen v_A=E5001_A
gen v_B=E5001_B
gen v_C=E5001_C
gen v_D=E5001_D
gen v_E=E5001_E
gen v_F=E5001_F
gen v_G=E5001_G
gen v_H=E5001_H
gen v_I=E5001_I

replace v_A=. if E3019_A==.
replace v_B=. if E3019_B==.
replace v_C=. if E3019_C==.
replace v_D=. if E3019_D==.
replace v_E=. if E3019_E==.
replace v_F=. if E3019_F==.
replace v_G=. if E3019_G==.
replace v_H=. if E3019_H==.
replace v_I=. if E3019_I==.

egen SPV=rowtotal (v_A v_B v_C v_D v_E v_F v_G v_H v_I)
label var SPV "Sum of all party vote shares in a country-election"

*(R's perception of pty LR position * pty vote share)/SPV
gen wRiVi_A=(E3019_A*v_A)/SPV
gen wRiVi_B=(E3019_B*v_B)/SPV
gen wRiVi_C=(E3019_C*v_C)/SPV
gen wRiVi_D=(E3019_D*v_D)/SPV
gen wRiVi_E=(E3019_E*v_E)/SPV
gen wRiVi_F=(E3019_F*v_F)/SPV
gen wRiVi_G=(E3019_G*v_G)/SPV
gen wRiVi_H=(E3019_H*v_H)/SPV
gen wRiVi_I=(E3019_I*v_I)/SPV

*pty system average LR position (based on respondents)
egen Rm=rowtotal (wRiVi_A wRiVi_B wRiVi_C wRiVi_D wRiVi_E wRiVi_F wRiVi_G wRiVi_H wRiVi_I)
label var Rm "R's based Party system average LR position"

*(R's party placement - Rm)/5
gen RiRm_A=(E3019_A - Rm)/5
gen RiRm_B=(E3019_B - Rm)/5
gen RiRm_C=(E3019_C - Rm)/5
gen RiRm_D=(E3019_D - Rm)/5
gen RiRm_E=(E3019_E - Rm)/5
gen RiRm_F=(E3019_F - Rm)/5
gen RiRm_G=(E3019_G - Rm)/5
gen RiRm_H=(E3019_H - Rm)/5
gen RiRm_I=(E3019_I - Rm)/5

*Square RiRm * Vote%
gen Xv_A=(RiRm_A*RiRm_A)*E5001_A
gen Xv_B=(RiRm_B*RiRm_B)*E5001_B
gen Xv_C=(RiRm_C*RiRm_C)*E5001_C
gen Xv_D=(RiRm_D*RiRm_D)*E5001_D
gen Xv_E=(RiRm_E*RiRm_E)*E5001_E
gen Xv_F=(RiRm_F*RiRm_F)*E5001_F
gen Xv_G=(RiRm_G*RiRm_G)*E5001_G
gen Xv_H=(RiRm_H*RiRm_H)*E5001_H
gen Xv_I=(RiRm_I*RiRm_I)*E5001_I

egen P=rowtotal (Xv_A Xv_B Xv_C Xv_D Xv_E Xv_F Xv_G Xv_H Xv_I)

*Square root of P
gen r_IP5=sqrt(P)
label var r_IP5 "R's ideological (LR) pty system polarization, CSES5"


*e_IP - Party system polarization based on expert pty LR placements using CSES5 data
*recoding missing values
replace E5018_A=. if E5018_A>10
replace E5018_B=. if E5018_B>10
replace E5018_C=. if E5018_C>10
replace E5018_D=. if E5018_D>10
replace E5018_E=. if E5018_E>10
replace E5018_F=. if E5018_F>10
replace E5018_G=. if E5018_G>10
replace E5018_H=. if E5018_H>10
replace E5018_I=. if E5018_I>10

gen ev_A=E5001_A
gen ev_B=E5001_B
gen ev_C=E5001_C
gen ev_D=E5001_D
gen ev_E=E5001_E
gen ev_F=E5001_F
gen ev_G=E5001_G
gen ev_H=E5001_H
gen ev_I=E5001_I

replace ev_A=. if E5018_A==.
replace ev_B=. if E5018_B==.
replace ev_C=. if E5018_C==.
replace ev_D=. if E5018_D==.
replace ev_E=. if E5018_E==.
replace ev_F=. if E5018_F==.
replace ev_G=. if E5018_G==.
replace ev_H=. if E5018_H==.
replace ev_I=. if E5018_I==.

egen eSPV=rowtotal (ev_A ev_B ev_C ev_D ev_E ev_F ev_G ev_H ev_I)
label var eSPV "Sum of all party vote shares in a country-election"

*Expert party LR placement * pty vote share/total party vote %
gen weRiVi_A=(E5018_A*ev_A)/eSPV
gen weRiVi_B=(E5018_B*ev_B)/eSPV
gen weRiVi_C=(E5018_C*ev_C)/eSPV
gen weRiVi_D=(E5018_D*ev_D)/eSPV
gen weRiVi_E=(E5018_E*ev_E)/eSPV
gen weRiVi_F=(E5018_F*ev_F)/eSPV
gen weRiVi_G=(E5018_G*ev_G)/eSPV
gen weRiVi_H=(E5018_H*ev_H)/eSPV
gen weRiVi_I=(E5018_I*ev_I)/eSPV

*pty system average LR position (based on experts)
egen eRm=rowtotal (weRiVi_A weRiVi_B weRiVi_C weRiVi_D weRiVi_E weRiVi_F weRiVi_G weRiVi_H weRiVi_I)
label var eRm "Expert-based party system average LR position"

*(Expert party placement - eRm)/5
gen eRiRm_A=(E5018_A - eRm)/5
gen eRiRm_B=(E5018_B - eRm)/5
gen eRiRm_C=(E5018_C - eRm)/5
gen eRiRm_D=(E5018_D - eRm)/5
gen eRiRm_E=(E5018_E - eRm)/5
gen eRiRm_F=(E5018_F - eRm)/5
gen eRiRm_G=(E5018_G - eRm)/5
gen eRiRm_H=(E5018_H - eRm)/5
gen eRiRm_I=(E5018_I - eRm)/5

*Square eRiRm * Vote%
gen eXv_A=(eRiRm_A*eRiRm_A)*E5001_A
gen eXv_B=(eRiRm_B*eRiRm_B)*E5001_B
gen eXv_C=(eRiRm_C*eRiRm_C)*E5001_C
gen eXv_D=(eRiRm_D*eRiRm_D)*E5001_D
gen eXv_E=(eRiRm_E*eRiRm_E)*E5001_E
gen eXv_F=(eRiRm_F*eRiRm_F)*E5001_F
gen eXv_G=(eRiRm_G*eRiRm_G)*E5001_G
gen eXv_H=(eRiRm_H*eRiRm_H)*E5001_H
gen eXv_I=(eRiRm_I*eRiRm_I)*E5001_I

egen eP=rowtotal (eXv_A eXv_B eXv_C eXv_D eXv_E eXv_F eXv_G eXv_H eXv_I)

gen e_IP5=sqrt(eP)
label var e_IP5 "Expert-based ideological (LR) pty system polarization"

drop Xv_A Xv_B Xv_C Xv_D Xv_E Xv_F Xv_G Xv_H Xv_I
drop RiRm_A RiRm_B RiRm_C RiRm_D RiRm_E RiRm_F RiRm_G RiRm_H RiRm_I
drop wRiVi_A wRiVi_B wRiVi_C wRiVi_D wRiVi_E wRiVi_F wRiVi_G wRiVi_H wRiVi_I

drop eXv_A eXv_B eXv_C eXv_D eXv_E eXv_F eXv_G eXv_H eXv_I
drop eRiRm_A eRiRm_B eRiRm_C eRiRm_D eRiRm_E eRiRm_F eRiRm_G eRiRm_H eRiRm_I
drop weRiVi_A weRiVi_B weRiVi_C weRiVi_D weRiVi_E weRiVi_F weRiVi_G weRiVi_H weRiVi_I
drop SPV eSPV Rm eRm P eP
drop ev_A ev_B ev_C ev_D ev_E ev_F ev_G ev_H ev_I
drop v_A v_B v_C v_D v_E v_F v_G v_H v_I

gen r_IP=.
replace r_IP=r_IP14 if module<5
replace r_IP=r_IP5 if module==5
replace r_IP=10 if r_IP1>10
label var r_IP "R's ideological (LR) pty system polarization"
drop r_IP14 r_IP5

gen e_IP=. 
replace e_IP=e_IP14 if module<5
replace e_IP=e_IP5 if module==5
label var e_IP "Expert-based ideological (LR) pty system polarization"
drop e_IP14 e_IP5

*Partisanship (dichotomous)
gen PID14=.
replace PID14=1 if IMD3005_1==1
replace PID14=0 if IMD3005_1==0

gen PID5=.
replace PID5=1 if E3024_1==1
replace PID5=0 if E3024_1==0

gen PID=.
replace PID=PID14 if module<5
replace PID=PID5 if module==5

label var PID "Partisanship (dichotomous)"
label define PID_label 0"no" 1"yes" 
label values PID PID_label
drop PID14 PID5

*Partisanship (extended)
gen winner=0
label var winner "1 - feels close to pty that won current election, 0-otherwise"

*ALB_2005
replace winner=1 if IMD1004=="ALB_2005" & (IMD3005_3==80002 | IMD3005_3==80001 | IMD3005_3==80030 | IMD3005_3==80031)

*ARG_2015
replace winner=1 if IMD1004=="ARG_2015" & (IMD3005_3==320002 | IMD3005_3==320007 | IMD3005_3==320008)

*AUS_1996
replace winner=1 if IMD1004=="AUS_1996" & (IMD3005_3==0360001 | IMD3005_3==0360002)
*AUS_2004
replace winner=1 if IMD1004=="AUS_2004" & (IMD3005_3==0360001 | IMD3005_3==0360002)
*AUS_2007
replace winner=1 if IMD1004=="AUS_2007" & (IMD3005_3==0360003)
*AUS_2013
replace winner=1 if IMD1004=="AUS_2013" & (IMD3005_3==360001 | IMD3005_3==360002)

*AUT_2008
replace winner=1 if IMD1004=="AUT_2008" & (IMD3005_3==400001 | IMD3005_3==400002)
*AUT_2013
replace winner=1 if IMD1004=="AUT_2013" & (IMD3005_3==400001 | IMD3005_3==400002)

*BELF1999
replace winner=1 if IMD1004=="BELF1999" & (IMD3005_3==560004 | IMD3005_3==560005 | IMD3005_3==560016 | IMD3005_3==560002 | IMD3005_3==560013)

*BGR_2001
replace winner=1 if IMD1004=="BGR_2001" & (IMD3005_3==1000019 | IMD3005_3==1000002 | IMD3005_3==1000003)
*BGR_2014
replace winner=1 if IMD1004=="BGR_2014" & (IMD3005_3==1000001 | IMD3005_3==1000004 | IMD3005_3==1000008)

*BRA_2002
replace winner=1 if IMD1004=="BRA_2002" & (IMD3005_3==760001 | IMD3005_3==760005 | IMD3005_3==760011 | IMD3005_3==760010 | IMD3005_3==760046)
*BRA_2006
replace winner=1 if IMD1004=="BRA_2006" & (IMD3005_3==760003 | IMD3005_3==760001 | IMD3005_3==760011 | IMD3005_3==760010)
*BRA_2010
replace winner=1 if IMD1004=="BRA_2010" & (IMD3005_3==760001 | IMD3005_3==760003 | IMD3005_3==760007 | IMD3005_3==760005 | IMD3005_3==760004 | IMD3005_3==760011)
*BRA_2014
replace winner=1 if IMD1004=="BRA_2014" & (IMD3005_3==760001 | IMD3005_3==760003 | IMD3005_3==760004 | IMD3005_3==760006 | IMD3005_3==760007 | IMD3005_3==760026)

*CAN_1997
replace winner=1 if IMD1004=="CAN_1997" & (IMD3005_3==1240001)
*CAN_2004
replace winner=1 if IMD1004=="CAN_2004" & (IMD3005_3==1240001)
*CAN_2008
replace winner=1 if IMD1004=="CAN_2008" & (IMD3005_3==1240002)
*CAN_2011
replace winner=1 if IMD1004=="CAN_2011" & (IMD3005_3==1240002)
*CAN_2015
replace winner=1 if IMD1004=="CAN_2015" & (IMD3005_3==1240001)

*CHE_1999
replace winner=1 if IMD1004=="CHE_1999" & (IMD3005_3==7560002 | IMD3005_3==7560001 | IMD3005_3==7560024 | IMD3005_3==7560003)
*CHE_2003
replace winner=1 if IMD1004=="CHE_2003" & (IMD3005_3==7560002 | IMD3005_3==7560001 | IMD3005_3==7560024 | IMD3005_3==7560003)
*CHE_2007
replace winner=1 if IMD1004=="CHE_2007" & (IMD3005_3==7560002 | IMD3005_3==7560001 | IMD3005_3==7560024 | IMD3005_3==7560003)
*CHE_2011
replace winner=1 if IMD1004=="CHE_2011" & (IMD3005_3==7560001 | IMD3005_3==7560002 | IMD3005_3==7560003 | IMD3005_3==7560004 | IMD3005_3==7560008)

*CHL_2005
replace winner=1 if IMD1004=="CHL_2005" & (IMD3005_3==1520001 | IMD3005_3==1520005 | IMD3005_3==1520004 | IMD3005_3==1520007)
*CHL_2009 - no data on this variable 
replace winner=. if IMD1004=="CHL_2009"

*CZE_1996
replace winner=1 if IMD1004=="CZE_1996" & (IMD3005_3==2030002 | IMD3005_3==2030003 | IMD3005_3==2030011)
*CZE_2002
replace winner=1 if IMD1004=="CZE_2002" & (IMD3005_3==2030001 | IMD3005_3==2030003 | IMD3005_3==2030017)
*CZE_2006
replace winner=1 if IMD1004=="CZE_2006" & (IMD3005_3==2030002)
*CZE_2010
replace winner=1 if IMD1004=="CZE_2010" & (IMD3005_3==2030002 | IMD3005_3==2030010 | IMD3005_3==2030014)
*CZE_2013
replace winner=1 if IMD1004=="CZE_2013" & (IMD3005_3==2030001 | IMD3005_3==2030006 | IMD3005_3==2030003)

*DEU12002
replace winner=1 if IMD1004=="DEU12002" & (IMD3005_3==2760004 | IMD3005_3==2760005)
*DEU22002
replace winner=1 if IMD1004=="DEU22002" & (IMD3005_3==2760004 | IMD3005_3==2760005)
*DEU_1998
replace winner=1 if IMD1004=="DEU_1998" & (IMD3005_3==2760004 | IMD3005_3==2760005)
*DEU_2005
replace winner=1 if IMD1004=="DEU_2005" & (IMD3005_3==2760004 | IMD3005_3==2760002 | IMD3005_3==2760003)
*DEU_2009
replace winner=1 if IMD1004=="DEU_2009" & (IMD3005_3==2760002 | IMD3005_3==2760006 | IMD3005_3==2760003)
*DEU_2013
replace winner=1 if IMD1004=="DEU_2013" & (IMD3005_3==2760002 | IMD3005_3==2760004 | IMD3005_3==2760003)

*DNK_1998
replace winner=1 if IMD1004=="DNK_1998" & (IMD3005_3==2080001 | IMD3005_3==2080006)
*DNK_2001
replace winner=1 if IMD1004=="DNK_2001" & (IMD3005_3==2080002 | IMD3005_3==2080007)
*DNK_2007
replace winner=1 if IMD1004=="DNK_2007" & (IMD3005_3==2080002 | IMD3005_3==2080007)

*ESP_1996
replace winner=1 if IMD1004=="ESP_1996" & (IMD3005_3==7240002)
*ESP_2004
replace winner=1 if IMD1004=="ESP_2004" & (IMD3005_3==7240001)
*ESP_2008
replace winner=1 if IMD1004=="ESP_2008" & (IMD3005_3==7240001)

*EST_2011
replace winner=1 if IMD1004=="EST_2011" & (IMD3005_3==2330001 | IMD3005_3==2330004)

*FIN_2003
replace winner=1 if IMD1004=="FIN_2003" & (IMD3005_3==2460001 | IMD3005_3==2460002 | IMD3005_3==2460008)
*FIN_2007
replace winner=1 if IMD1004=="FIN_2007" & (IMD3005_3==2460001 | IMD3005_3==2460003 | IMD3005_3==2460005 | IMD3005_3==2460008)
*FIN_2011
replace winner=1 if IMD1004=="FIN_2011" & (IMD3005_3==2460003 | IMD3005_3==2460002 | IMD3005_3==2460006 | IMD3005_3==2460005 | IMD3005_3==2460008 | IMD3005_3==2460007)
*FIN_2015
replace winner=1 if IMD1004=="FIN_2015" & (IMD3005_3==2460001 | IMD3005_3==2460003 | IMD3005_3==2460004)

*FRA_2007
replace winner=1 if IMD1004=="FRA_2007" & (IMD3005_3==2500001 | IMD3005_3==2500002)

*GBR_1997
replace winner=1 if IMD1004=="GBR_1997" & (IMD3005_3==8260002)
*GBR_2005
replace winner=1 if IMD1004=="GBR_2005" & (IMD3005_3==8260002)
*GBR_2015
replace winner=1 if IMD1004=="GBR_2015" & (IMD3005_3==8260001)

*GRC_2009
replace winner=1 if IMD1004=="GRC_2009" & (IMD3005_3==3000001)
*GRC_2012
replace winner=1 if IMD1004=="GRC_2012" & (IMD3005_3==3000002 | IMD3005_3==3000001 | IMD3005_3==3000012)
*GRC_2015 
replace winner=1 if IMD1004=="GRC_2015" & (IMD3005_3==3000003 | IMD3005_3==3000007) 
replace winner=1 if IMD1004=="GRC_2015" & (E3024_3==300001 | E3024_3==300007) 

*HRV_2007
replace winner=1 if IMD1004=="HRV_2007" & (IMD3005_3==1910001 | IMD3005_3==1910007 | IMD3005_3==1910008)

*HUN_1998
replace winner=1 if IMD1004=="HUN_1998" & (IMD3005_3==3480002 | IMD3005_3==3480013 | IMD3005_3==3480007)
*HUN_2002 
replace winner=1 if IMD1004=="HUN_2002" & (IMD3005_3==3480001 | IMD3005_3==3480008)

*IRL_2002
replace winner=1 if IMD1004=="IRL_2002" & (IMD3005_3==3720001 | IMD3005_3==3720006)
*IRL_2007 - no data on this variable
replace winner=. if IMD1004=="IRL_2007" 
*IRL_2011
replace winner=1 if IMD1004=="IRL_2011" & (IMD3005_3==3720002 | IMD3005_3==3720003)

*ISL_1999
replace winner=1 if IMD1004=="ISL_1999" & (IMD3005_3==3520001 | IMD3005_3==3520003)
*ISL_2003
replace winner=1 if IMD1004=="ISL_2003" & (IMD3005_3==3520001 | IMD3005_3==3520003)
*ISL_2007
replace winner=1 if IMD1004=="ISL_2007" & (IMD3005_3==3520001 | IMD3005_3==3520002)
*ISL_2009
replace winner=1 if IMD1004=="ISL_2009" & (IMD3005_3==3520002 | IMD3005_3==3520005)
*ISL_2013
replace winner=1 if IMD1004=="ISL_2013" & (IMD3005_3==3520001 | IMD3005_3==3520003)

*ISR_1996
replace winner=1 if IMD1004=="ISR_1996" & (IMD3005_3==3760001 | IMD3005_3==3760047 | IMD3005_3==3760066 | IMD3005_3==3760046 | IMD3005_3==3760031 | IMD3005_3==3760003 | IMD3005_3==3760014)
*ISR_2003
replace winner=1 if IMD1004=="ISR_2003" & (IMD3005_3==3760001 | IMD3005_3==3760015 | IMD3005_3==3760049)
*ISR_2006
replace winner=1 if IMD1004=="ISR_2006" & (IMD3005_3==3760016 | IMD3005_3==3760002 | IMD3005_3==3760003 | IMD3005_3==3760048)
*ISR_2013
replace winner=1 if IMD1004=="ISR_2013" & (IMD3005_3==3760011 | IMD3005_3==3760007 | IMD3005_3==3760008 | IMD3005_3==3760009)

*ITA_2006
replace winner=1 if IMD1004=="ITA_2006" & (IMD3005_3==3800011 | IMD3005_3==3800021 | IMD3005_3==3800013)

*KEN_2013
replace winner=1 if IMD1004=="KEN_2013" & (IMD3005_3==4040100 | IMD3005_3==4040101)

*KOR_2000
replace winner=1 if IMD1004=="KOR_2000" & (IMD3005_3==4100011 | IMD3005_3==4100012 | IMD3005_3==4100018)
*KOR_2004
replace winner=1 if IMD1004=="KOR_2004" & (IMD3005_3==4100021)
*KOR_2008
replace winner=1 if IMD1004=="KOR_2008" & (IMD3005_3==4100001)

*LVA_2011
replace winner=1 if IMD1004=="LVA_2011" & (IMD3005_3==4280007 | IMD3005_3==4280002 | IMD3005_3==4280003)
*LVA_2014
replace winner=1 if IMD1004=="LVA_2014" & (IMD3005_3==4280002 | IMD3005_3==4280005 | IMD3005_3==4280003)

*MEX_1997
replace winner=1 if IMD1004=="MEX_1997" & (IMD3005_3==4840003 | IMD3005_3==4840002)
*MEX_2000
replace winner=1 if IMD1004=="MEX_2000" & (IMD3005_3==4840002 | IMD3005_3==4840005)
*MEX_2003
replace winner=1 if IMD1004=="MEX_2003" & (IMD3005_3==4840002 | IMD3005_3==4840001)
*MEX_2006
replace winner=1 if IMD1004=="MEX_2006" & (IMD3005_3==4840002 | IMD3005_3==4840001)
*MEX_2009
replace winner=1 if IMD1004=="MEX_2009" & (IMD3005_3==4840002)
*MEX_2012
replace winner=1 if IMD1004=="MEX_2012" & (IMD3005_3==4840001 | IMD3005_3==4840005)
*MEX_2015
replace winner=1 if IMD1004=="MEX_2015" & (IMD3005_3==4840001 | IMD3005_3==4840015)

*MNE_2012
replace winner=1 if IMD1004=="MNE_2012" & (IMD3005_3==4990001 | IMD3005_3==4990004 | IMD3005_3==4990009 | IMD3005_3==4990007)

*NLD_1998
replace winner=1 if IMD1004=="NLD_1998" & (IMD3005_3==5280002 | IMD3005_3==5280003 | IMD3005_3==5280004)
*NLD_2002
replace winner=1 if IMD1004=="NLD_2002" & (IMD3005_3==5280001 | IMD3005_3==5280014 | IMD3005_3==5280003)
*NLD_2006
replace winner=1 if IMD1004=="NLD_2006" & (IMD3005_3==5280001 | IMD3005_3==5280002 | IMD3005_3==5280008)
*NLD_2010
replace winner=1 if IMD1004=="NLD_2010" & (IMD3005_3==5280003 | IMD3005_3==5280001)

*NOR_2001
replace winner=1 if IMD1004=="NOR_2001" & (IMD3005_3==5780002 | IMD3005_3==5780007 | IMD3005_3==5780008)
*NOR_2005
replace winner=1 if IMD1004=="NOR_2005" & (IMD3005_3==5780001 | IMD3005_3==5780004 | IMD3005_3==5780006)
*NOR_2009
replace winner=1 if IMD1004=="NOR_2009" & (IMD3005_3==5780001 | IMD3005_3==5780004 | IMD3005_3==5780006)
*NOR_2013
replace winner=1 if IMD1004=="NOR_2013" & (IMD3005_3==5780002 | IMD3005_3==5780003)

*NZL_1996
replace winner=1 if IMD1004=="NZL_1996" & (IMD3005_3==5540001 | IMD3005_3==5540003)
*NZL_2002
replace winner=1 if IMD1004=="NZL_2002" & (IMD3005_3==5540002 | IMD3005_3==5540012)
*NZL_2008
replace winner=1 if IMD1004=="NZL_2008" & (IMD3005_3==5540001)
*NZL_2011
replace winner=1 if IMD1004=="NZL_2011" & (IMD3005_3==5540001)
*NZL_2014
replace winner=1 if IMD1004=="NZL_2014" & (IMD3005_3==5540001)

*PER_2006
replace winner=1 if IMD1004=="PER_2006" & (IMD3005_3==6040026)
*PER_2011
replace winner=1 if IMD1004=="PER_2011" & (IMD3005_3==6040050)
*PER_2016
replace winner=1 if IMD1004=="PER_2016" & (IMD3005_3==6040002)

*PHL_2016
replace winner=1 if IMD1004=="PHL_2016" & (IMD3005_3==6080004)

*POL_1997
replace winner=1 if IMD1004=="POL_1997" & (IMD3005_3==6160004 | IMD3005_3==6160008)
*POL_2001
replace winner=1 if IMD1004=="POL_2001" & (IMD3005_3==6160070 | IMD3005_3==6160003 | IMD3005_3==6160007)
*POL_2005
replace winner=1 if IMD1004=="POL_2005" & (IMD3005_3==6160002)
*POL_2007
replace winner=1 if IMD1004=="POL_2007" & (IMD3005_3==6160001 | IMD3005_3==6160003)
*POL_2011
replace winner=1 if IMD1004=="POL_2011" & (IMD3005_3==6160001 | IMD3005_3==6160003)

*PRT_2002
replace winner=1 if IMD1004=="PRT_2002" & (IMD3005_3==6200001 | IMD3005_3==6200003)
*PRT_2005
replace winner=1 if IMD1004=="PRT_2005" & (IMD3005_3==6200002)
*PRT_2009
replace winner=1 if IMD1004=="PRT_2009" & (IMD3005_3==6200002)
*PRT_2015
replace winner=1 if IMD1004=="PRT_2015" & (IMD3005_3==6200002)

*ROU_1996
replace winner=1 if IMD1004=="ROU_1996" & (IMD3005_3==6420019 | IMD3005_3==6420005 | IMD3005_3==6420007 | IMD3005_3==6420001 | IMD3005_3==6420003)
*ROU_2004
replace winner=1 if IMD1004=="ROU_2004" & (IMD3005_3==6420005 | IMD3005_3==6420019 | IMD3005_3==6420003 | IMD3005_3==6420024)
*ROU_2012
replace winner=1 if IMD1004=="ROU_2012" & (IMD3005_3==6420011 | IMD3005_3==6420001 | IMD3005_3==6420005)

*RUS_1999
replace winner=1 if IMD1004=="RUS_1999" & (IMD3005_3==6430051 | IMD3005_3==6430022)

*SRB_2012
replace winner=1 if IMD1004=="SRB_2012" & (IMD3005_3==6880001 | IMD3005_3==6880004 | IMD3005_3==6880007)

*SVK_2010
replace winner=1 if IMD1004=="SVK_2010" & (IMD3005_3==7030003 | IMD3005_3==7030002 | IMD3005_3==7030004 | IMD3005_3==7030008)
*SVK_2016
replace winner=1 if IMD1004=="SVK_2016" & (IMD3005_3==7030001 | IMD3005_3==7030006 | IMD3005_3==7030008 | IMD3005_3==7030013)

*SVN_1996
replace winner=1 if IMD1004=="SVN_1996" & (IMD3005_3==7050003 | IMD3005_3==7050004 | IMD3005_3==7050006)
*SVN_2004
replace winner=1 if IMD1004=="SVN_2004" & (IMD3005_3==7050001 | IMD3005_3==7050007 | IMD3005_3==7050006 | IMD3005_3==3)
*SVN_2008
replace winner=1 if IMD1004=="SVN_2008" & (IMD3005_3==7050002 | IMD3005_3==7050020 | IMD3005_3==7050003 | IMD3005_3==7050004)
*SVN_2011
replace winner=1 if IMD1004=="SVN_2011" & (IMD3005_3==7050001 | IMD3005_3==7050009 | IMD3005_3==7050003 | IMD3005_3==7050006 | IMD3005_3==7050007)

*SWE_1998
replace winner=1 if IMD1004=="SWE_1998" & (IMD3005_3==7520001)
*SWE_2002
replace winner=1 if IMD1004=="SWE_2002" & (IMD3005_3==7520001)
*SWE_2006
replace winner=1 if IMD1004=="SWE_2006" & (IMD3005_3==7520002 | IMD3005_3==7520006 | IMD3005_3==7520003 | IMD3005_3==7520004)
*SWE_2014
replace winner=1 if IMD1004=="SWE_2014" & (IMD3005_3==7520001 | IMD3005_3==7520005)

*TUR_2011
replace winner=1 if IMD1004=="TUR_2011" & (IMD3005_3==7920001)
*TUR_2015
replace winner=1 if IMD1004=="TUR_2015" & (IMD3005_3==7920001)

*UKR_1998
replace winner=1 if IMD1004=="UKR_1998" & (IMD3005_3==8040015 | IMD3005_3==8040016 | IMD3005_3==8040020)

*URY_2009
replace winner=1 if IMD1004=="URY_2009" & (IMD3005_3==8580001)

*USA_2004
replace winner=1 if IMD1004=="USA_2004" & (IMD3005_3==8400001)
*USA_2008
replace winner=1 if IMD1004=="USA_2008" & (IMD3005_3==8400002)
*USA_2012
replace winner=1 if IMD1004=="USA_2012" & (IMD3005_3==8400001)

*ZAF_2014
replace winner=1 if IMD1004=="ZAF_2014" & (IMD3005_3==7100001)

*Additional countries from the Module 5
*AUT_2017
replace winner=1 if IMD1004=="AUT_2017" & (E3024_3==40001 | E3024_3==40003)

*BRA_2018
replace winner=1 if IMD1004=="BRA_2018" & (E3024_3==76001 | E3024_3==76027 | E3024_3==76010 | E3024_3==76004 | E3024_3==76006 | E3024_3==76009 | E3024_3==76008)

*CHL_2017 - no data on this variable
replace winner=. if IMD1004=="CHL_2017"

*DEU_2017
replace winner=1 if IMD1004=="DEU_2017" & (E3024_3==276001 | E3024_3==276002 | E3024_3==276007)

*HUN_2018
replace winner=1 if IMD1004=="HUN_2018" & (E3024_3==348001)

*IRL_2016
replace winner=1 if IMD1004=="IRL_2016" & (E3024_3==372001)

*ITA_2018
replace winner=1 if IMD1004=="ITA_2018" & (E3024_3==380001 | E3024_3==380003)

*KOR_2016 - no data on this variable
replace winner=. if IMD1004=="KOR_2016" 

*LTU_2016
replace winner=1 if IMD1004=="LTU_2016" & (E3024_3==440003 | E3024_3==440002)

*MNE_2016
replace winner=1 if IMD1004=="MNE_2016" & (E3024_3==499001 | E3024_3==499006 | E3024_3==499007 | E3024_3==499008 | E3024_3==499009)

*NOR_2017
replace winner=1 if IMD1004=="NOR_2017" & (E3024_3==578003 | E3024_3==578002)

*NZL_2017
replace winner=1 if IMD1004=="NZL_2017" & (E3024_3==554002 | E3024_3==554003)

*TUR_2018
replace winner=1 if IMD1004=="TUR_2018" & (E3024_3==792001)

replace winner=0 if PID==0

gen PID_full=.
label var PID_full "Partisanship (extended)"
replace PID_full=2 if (PID==1 & winner==1)
replace PID_full=1 if (PID==1 & winner==0)
replace PID_full=0 if PID==0
label define PIDfull_label 0"non-PID" 1"PID of nongov pty" 2"PID of gov pty"
label values PID_full PIDfull_label

*el_aut - Electoral autocracy
gen el_aut=0
label var el_aut "Electoral autocracy, V-dem 11 data, v2x_regime"
replace el_aut=1 if (IMD1004=="ALB_2005" | IMD1004=="HUN_2018" | IMD1004=="KEN_2013" | IMD1004=="MNE_2016" | IMD1004=="RUS_1999" | IMD1004=="TUR_2015" | IMD1004=="TUR_2018" | IMD1004=="UKR_1998")


*Left-right self-placement
gen lrscale=.
replace lrscale=IMD3006 if module<5
replace lrscale=E3020 if module==5
recode lrscale 95=. 97=. 98=. 99=.
label define lrscale_label 0"Left" 10"Right"
label values lrscale lrscale_label
label var lrscale "Left-right self-placement"

*Left-right extremity 
sort IMD1004
by IMD1004: egen LRmd=median(lrscale)
gen lr_extr=abs(lrscale - LRmd)
drop LRmd
label var lr_extr "LR extremity"

*Education 
gen edu14=IMD2003
recode edu14 6=. 7=. 8=. 9=.
gen edu5=E2003
recode edu5 96=. 97=. 98=. 99=.
recode edu5 1=0 2=1 3=1 4=2 5=3 6=3 7=4 8=4 9=4

gen edu=.
replace edu=edu14 if module<5
replace edu=edu5 if module==5
label define edu_label 0"none(no education)/illiterate" 1"primary edu/lower secondary edu" 2"higher secondary edu" 3"post-secondary (non-university) edu" 4"university edu"
label values edu edu_label
label var edu "highest education level completed"
drop edu14 edu5

*Income 
gen income=.
replace income=IMD2006 if module<5
replace income=E2010 if module==5
recode income 6=. 7=. 8=. 9=.
label define income_label 1"lowest income quintile" 2"second income quintile" 3"third income quintile" 4"fourth income quintile" 5"highest income quintile"
label values income income_label
label var income "household income quintile"

*Male
gen male=.
replace male=1 if (IMD2002==1 & module<5)
replace male=0 if (IMD2002==2 & module<5)
replace male=1 if (E2002==1 & module==5)
replace male=0 if (E2002==2 & module==5)
label var male "Male"

*Age
gen age14=IMD2001_1
recode age14 9997=. 9998=. 9999=.

gen b_year=E2001_Y
recode b_year 9997=. 9998=. 9999=.
gen age5=E1034-b_year if b_year!=.

gen age=.
replace age=age14 if module<5
replace age=age5 if module==5
drop age14 age5 b_year
label var age "Age"

*time_el - Time since election
gen time_el=.
replace time_el=IMD1014_1 if module<5
replace time_el=E1035_1 if module==5
replace time_el=. if time_el==9995
replace time_el=. if time_el==9999
label var time_el "Days between interview and first round of last elections"

*IMD1013_D - date questionnaire administered - day
*IMD1013_M - date questionnaire administered - month 
*IMD1013_Y - date questionnaire administered - year

*RUS_1999
*Election on December 19, 1999; Fieldwork 1999 Dec 25 - 2000 Jan 31
replace time_el= IMD1013_D - 19 if (IMD1004=="RUS_1999" & IMD1013_M==12)
replace time_el= (31-19)+IMD1013_D if (IMD1004=="RUS_1999" & IMD1013_M==1)

*ALB_2005
*Election on July 3, 2005; Fieldwork July 5-20
*no information on the day of interview in the date - average number of days since election assigned
replace time_el=10 if IMD1004=="ALB_2005"

*inst - Institutionalization 
gen inst=.
label var inst "pty institutionalization index, V-dem: v2xps_party"
replace inst=0.538 if IMD1004=="ALB_2005"
replace inst=0.703 if IMD1004=="ARG_2015"
replace inst=0.954 if IMD1004=="AUS_1996"
replace inst=0.952 if IMD1004=="AUS_2004"
replace inst=0.952 if IMD1004=="AUS_2007"
replace inst=0.938 if IMD1004=="AUS_2013"
replace inst=0.948 if IMD1004=="AUT_2008"
replace inst=0.955 if IMD1004=="AUT_2013"
replace inst=0.918 if IMD1004=="AUT_2017"
replace inst=0.972 if IMD1004=="BELF1999"
replace inst=0.772 if IMD1004=="BGR_2001"
replace inst=0.771 if IMD1004=="BGR_2014"
replace inst=0.686 if IMD1004=="BRA_2002"
replace inst=0.686 if IMD1004=="BRA_2006"
replace inst=0.686 if IMD1004=="BRA_2010"
replace inst=0.712 if IMD1004=="BRA_2014"
replace inst=0.721 if IMD1004=="BRA_2018"
replace inst=0.933 if IMD1004=="CAN_1997"
replace inst=0.954 if IMD1004=="CAN_2004"
replace inst=0.954 if IMD1004=="CAN_2008"
replace inst=0.957 if IMD1004=="CAN_2011"
replace inst=0.928 if IMD1004=="CAN_2015"
replace inst=0.87 if IMD1004=="CHE_1999"
replace inst=0.906 if IMD1004=="CHE_2003"
replace inst=0.906 if IMD1004=="CHE_2007"
replace inst=0.906 if IMD1004=="CHE_2011"
replace inst=0.936 if IMD1004=="CHL_2005"
replace inst=0.933 if IMD1004=="CHL_2009"
replace inst=0.947 if IMD1004=="CHL_2017"
replace inst=0.92 if IMD1004=="CZE_1996"
replace inst=0.929 if IMD1004=="CZE_2002"
replace inst=0.929 if IMD1004=="CZE_2006"
replace inst=0.929 if IMD1004=="CZE_2010"
replace inst=0.891 if IMD1004=="CZE_2013"
replace inst=0.995 if IMD1004=="DEU12002"
replace inst=0.995 if IMD1004=="DEU22002"
replace inst=0.995 if IMD1004=="DEU_1998"
replace inst=0.995 if IMD1004=="DEU_2005"
replace inst=0.995 if IMD1004=="DEU_2009"
replace inst=0.977 if IMD1004=="DEU_2013"
replace inst=0.963 if IMD1004=="DEU_2017"
replace inst=0.992 if IMD1004=="DNK_1998"
replace inst=0.992 if IMD1004=="DNK_2001"
replace inst=0.992 if IMD1004=="DNK_2007"
replace inst=0.985 if IMD1004=="ESP_1996"
replace inst=0.985 if IMD1004=="ESP_2004"
replace inst=0.985 if IMD1004=="ESP_2008"
replace inst=0.923 if IMD1004=="EST_2011"
replace inst=0.943 if IMD1004=="FIN_2003"
replace inst=0.943 if IMD1004=="FIN_2007"
replace inst=0.943 if IMD1004=="FIN_2011"
replace inst=0.955 if IMD1004=="FIN_2015"
replace inst=0.935 if IMD1004=="FRA_2007"
replace inst=0.949 if IMD1004=="GBR_1997"
replace inst=0.951 if IMD1004=="GBR_2005"
replace inst=0.941 if IMD1004=="GBR_2015"
replace inst=0.896 if IMD1004=="GRC_2009"
replace inst=0.886 if IMD1004=="GRC_2012"
replace inst=0.888 if IMD1004=="GRC_2015"
replace inst=0.8 if IMD1004=="HRV_2007"
replace inst=0.905 if IMD1004=="HUN_1998"
replace inst=0.905 if IMD1004=="HUN_2002"
replace inst=0.869 if IMD1004=="HUN_2018"
replace inst=0.908 if IMD1004=="IRL_2002"
replace inst=0.908 if IMD1004=="IRL_2007"
replace inst=0.907 if IMD1004=="IRL_2011"
replace inst=0.902 if IMD1004=="IRL_2016"
replace inst=0.92 if IMD1004=="ISL_1999"
replace inst=0.951 if IMD1004=="ISL_2003"
replace inst=0.951 if IMD1004=="ISL_2007"
replace inst=0.951 if IMD1004=="ISL_2009"
replace inst=0.893 if IMD1004=="ISL_2013"
replace inst=0.926 if IMD1004=="ISR_1996"
replace inst=0.913 if IMD1004=="ISR_2003"
replace inst=0.913 if IMD1004=="ISR_2006"
replace inst=0.909 if IMD1004=="ISR_2013"
replace inst=0.925 if IMD1004=="ITA_2006"
replace inst=0.929 if IMD1004=="ITA_2018"
replace inst=0.62 if IMD1004=="KEN_2013"
replace inst=0.914 if IMD1004=="KOR_2000"
replace inst=0.898 if IMD1004=="KOR_2004"
replace inst=0.898 if IMD1004=="KOR_2008"
replace inst=0.88 if IMD1004=="KOR_2016"
replace inst=0.891 if IMD1004=="LTU_2016"
replace inst=0.744 if IMD1004=="LVA_2011"
replace inst=0.759 if IMD1004=="LVA_2014"
replace inst=0.894 if IMD1004=="MEX_1997"
replace inst=0.918 if IMD1004=="MEX_2000"
replace inst=0.918 if IMD1004=="MEX_2003"
replace inst=0.918 if IMD1004=="MEX_2006"
replace inst=0.918 if IMD1004=="MEX_2009"
replace inst=0.911 if IMD1004=="MEX_2012"
replace inst=0.875 if IMD1004=="MEX_2015"
replace inst=0.837 if IMD1004=="MNE_2012"
replace inst=0.741 if IMD1004=="MNE_2016"
replace inst=0.988 if IMD1004=="NLD_1998"
replace inst=0.988 if IMD1004=="NLD_2002"
replace inst=0.977 if IMD1004=="NLD_2006"
replace inst=0.977 if IMD1004=="NLD_2010"
replace inst=0.977 if IMD1004=="NOR_2001"
replace inst=0.977 if IMD1004=="NOR_2005"
replace inst=0.977 if IMD1004=="NOR_2009"
replace inst=0.978 if IMD1004=="NOR_2013"
replace inst=0.973 if IMD1004=="NOR_2017"
replace inst=0.922 if IMD1004=="NZL_1996"
replace inst=0.922 if IMD1004=="NZL_2002"
replace inst=0.922 if IMD1004=="NZL_2008"
replace inst=0.922 if IMD1004=="NZL_2011"
replace inst=0.922 if IMD1004=="NZL_2014"
replace inst=0.918 if IMD1004=="NZL_2017"
replace inst=0.402 if IMD1004=="PER_2006"
replace inst=0.409 if IMD1004=="PER_2011"
replace inst=0.402 if IMD1004=="PER_2016"
replace inst=0.184 if IMD1004=="PHL_2016"
replace inst=0.871 if IMD1004=="POL_1997"
replace inst=0.913 if IMD1004=="POL_2001"
replace inst=0.916 if IMD1004=="POL_2005"
replace inst=0.93 if IMD1004=="POL_2007"
replace inst=0.916 if IMD1004=="POL_2011"
replace inst=0.931 if IMD1004=="PRT_2002"
replace inst=0.937 if IMD1004=="PRT_2005"
replace inst=0.937 if IMD1004=="PRT_2009"
replace inst=0.959 if IMD1004=="PRT_2015"
replace inst=0.625 if IMD1004=="ROU_1996"
replace inst=0.886 if IMD1004=="ROU_2004"
replace inst=0.869 if IMD1004=="ROU_2012"
replace inst=0.658 if IMD1004=="RUS_1999"
replace inst=0.766 if IMD1004=="SRB_2012"
replace inst=0.875 if IMD1004=="SVK_2010"
replace inst=0.838 if IMD1004=="SVK_2016"
replace inst=0.82 if IMD1004=="SVN_1996"
replace inst=0.837 if IMD1004=="SVN_2004"
replace inst=0.841 if IMD1004=="SVN_2008"
replace inst=0.844 if IMD1004=="SVN_2011"
replace inst=0.999 if IMD1004=="SWE_1998"
replace inst=1 if IMD1004=="SWE_2002"
replace inst=1 if IMD1004=="SWE_2006"
replace inst=0.993 if IMD1004=="SWE_2014"
replace inst=0.886 if IMD1004=="TUR_2011"
replace inst=0.913 if IMD1004=="TUR_2015"
replace inst=0.906 if IMD1004=="TUR_2018"
replace inst=0.454 if IMD1004=="UKR_1998"
replace inst=0.972 if IMD1004=="URY_2009"
replace inst=0.91 if IMD1004=="USA_2004"
replace inst=0.913 if IMD1004=="USA_2008"
replace inst=0.924 if IMD1004=="USA_2012"
replace inst=0.804 if IMD1004=="ZAF_2014"


*ENEP - Effective number of electoral parties
gen ENEP=. 
replace ENEP=IMD5058_1 if module<5
recode ENEP 999=.
replace ENEP=E5078 if module==5
replace ENEP=9 if IMD1004=="UKR_1998"
label var ENEP "Effective Number of Electoral Parties"

*av_DM - Average district magnitude
gen av_DM=.
replace av_DM=IMD5045_1 if module<5
replace av_DM=E5061 if module==5
label var av_DM "Average district magnitude, lower house, lowest tier"

*gini1 - Income inequality
gen gini=.
label var gini "Solt's gini1 index in disposable (post-tax, post-transfer) income"
replace gini=38.6 if IMD1004=="ALB_2005"
replace gini=37.7 if IMD1004=="ARG_2015"
replace gini=30.7 if IMD1004=="AUS_1996"
replace gini=31.7 if IMD1004=="AUS_2004"
replace gini=32.4 if IMD1004=="AUS_2007"
replace gini=32.6 if IMD1004=="AUS_2013"
replace gini=27.9 if IMD1004=="AUT_2008"
replace gini=27.8 if IMD1004=="AUT_2013"
replace gini=27.6 if IMD1004=="AUT_2017"
replace gini=26.5 if IMD1004=="BELF1999"
replace gini=32.2 if IMD1004=="BGR_2001"
replace gini=36.1 if IMD1004=="BGR_2014"
replace gini=52.3 if IMD1004=="BRA_2002"
replace gini=50.2 if IMD1004=="BRA_2006"
replace gini=47.4 if IMD1004=="BRA_2010"
replace gini=46.3 if IMD1004=="BRA_2014"
replace gini=47.9 if IMD1004=="BRA_2018"
replace gini=29.7 if IMD1004=="CAN_1997"
replace gini=31.3 if IMD1004=="CAN_2004"
replace gini=31.1 if IMD1004=="CAN_2008"
replace gini=31.1 if IMD1004=="CAN_2011"
replace gini=31.6 if IMD1004=="CAN_2015"
replace gini=28.6 if IMD1004=="CHE_1999"
replace gini=28.1 if IMD1004=="CHE_2003"
replace gini=30 if IMD1004=="CHE_2007"
replace gini=29.3 if IMD1004=="CHE_2011"
replace gini=48.6 if IMD1004=="CHL_2005"
replace gini=47.4 if IMD1004=="CHL_2009"
replace gini=45.8 if IMD1004=="CHL_2017"
replace gini=25 if IMD1004=="CZE_1996"
replace gini=25.5 if IMD1004=="CZE_2002"
replace gini=25.5 if IMD1004=="CZE_2006"
replace gini=25.3 if IMD1004=="CZE_2010"
replace gini=25.3 if IMD1004=="CZE_2013"
replace gini=27 if IMD1004=="DEU12002"
replace gini=27 if IMD1004=="DEU22002"
replace gini=25.7 if IMD1004=="DEU_1998"
replace gini=28.4 if IMD1004=="DEU_2005"
replace gini=28.7 if IMD1004=="DEU_2009"
replace gini=29.1 if IMD1004=="DEU_2013"
replace gini=29.4 if IMD1004=="DEU_2017"
replace gini=22.3 if IMD1004=="DNK_1998"
replace gini=22.8 if IMD1004=="DNK_2001"
replace gini=24.2 if IMD1004=="DNK_2007"
replace gini=31.9 if IMD1004=="ESP_1996"
replace gini=31.2 if IMD1004=="ESP_2004"
replace gini=32.1 if IMD1004=="ESP_2008"
replace gini=32.6 if IMD1004=="EST_2011"
replace gini=25.1 if IMD1004=="FIN_2003"
replace gini=25.7 if IMD1004=="FIN_2007"
replace gini=25.5 if IMD1004=="FIN_2011"
replace gini=25.5 if IMD1004=="FIN_2015"
replace gini=28.7 if IMD1004=="FRA_2007"
replace gini=33.8 if IMD1004=="GBR_1997"
replace gini=33.8 if IMD1004=="GBR_2005"
replace gini=33.2 if IMD1004=="GBR_2015"
replace gini=32.5 if IMD1004=="GRC_2009"
replace gini=33.3 if IMD1004=="GRC_2012"
replace gini=32.8 if IMD1004=="GRC_2015"
replace gini=27.5 if IMD1004=="HRV_2007"
replace gini=27.3 if IMD1004=="HUN_1998"
replace gini=27.3 if IMD1004=="HUN_2002"
replace gini=27.9 if IMD1004=="HUN_2018"
replace gini=31.4 if IMD1004=="IRL_2002"
replace gini=30.8 if IMD1004=="IRL_2007"
replace gini=30.5 if IMD1004=="IRL_2011"
replace gini=30 if IMD1004=="IRL_2016"
replace gini=29.6 if IMD1004=="ISL_1999"
replace gini=29.6 if IMD1004=="ISL_2003"
replace gini=28.8 if IMD1004=="ISL_2007"
replace gini=27.2 if IMD1004=="ISL_2009"
replace gini=24.9 if IMD1004=="ISL_2013"
replace gini=33.2 if IMD1004=="ISR_1996"
replace gini=35.8 if IMD1004=="ISR_2003"
replace gini=36.6 if IMD1004=="ISR_2006"
replace gini=36.3 if IMD1004=="ISR_2013"
replace gini=32.8 if IMD1004=="ITA_2006"
replace gini=33.8 if IMD1004=="ITA_2018"
replace gini=46.4 if IMD1004=="KEN_2013"
replace gini=31 if IMD1004=="KOR_2000"
replace gini=31 if IMD1004=="KOR_2004"
replace gini=31.4 if IMD1004=="KOR_2008"
replace gini=33.2 if IMD1004=="KOR_2016"
replace gini=36.1 if IMD1004=="LTU_2016"
replace gini=35.5 if IMD1004=="LVA_2011"
replace gini=35.1 if IMD1004=="LVA_2014"
replace gini=49.2 if IMD1004=="MEX_1997"
replace gini=48.7 if IMD1004=="MEX_2000"
replace gini=47.6 if IMD1004=="MEX_2003"
replace gini=46.4 if IMD1004=="MEX_2006"
replace gini=46 if IMD1004=="MEX_2009"
replace gini=45.2 if IMD1004=="MEX_2012"
replace gini=44 if IMD1004=="MEX_2015"
replace gini=38.5 if IMD1004=="MNE_2012"
replace gini=38.3 if IMD1004=="MNE_2016"
replace gini=32.9 if IMD1004=="NLD_1998"
replace gini=32.5 if IMD1004=="NLD_2002"
replace gini=32.1 if IMD1004=="NLD_2006"
replace gini=31.8 if IMD1004=="NLD_2010"
replace gini=24.8 if IMD1004=="NOR_2001"
replace gini=26.2 if IMD1004=="NOR_2005"
replace gini=24.6 if IMD1004=="NOR_2009"
replace gini=25.2 if IMD1004=="NOR_2013"
replace gini=25.8 if IMD1004=="NOR_2017"
replace gini=33 if IMD1004=="NZL_1996"
replace gini=32.5 if IMD1004=="NZL_2002"
replace gini=31.9 if IMD1004=="NZL_2008"
replace gini=31.9 if IMD1004=="NZL_2011"
replace gini=32.6 if IMD1004=="NZL_2014"
replace gini=32.8 if IMD1004=="NZL_2017"
replace gini=51.5 if IMD1004=="PER_2006"
replace gini=46.5 if IMD1004=="PER_2011"
replace gini=45.1 if IMD1004=="PER_2016"
replace gini=41 if IMD1004=="PHL_2016"
replace gini=28.6 if IMD1004=="POL_1997"
replace gini=29.5 if IMD1004=="POL_2001"
replace gini=31.9 if IMD1004=="POL_2005"
replace gini=31.3 if IMD1004=="POL_2007"
replace gini=30.8 if IMD1004=="POL_2011"
replace gini=33.8 if IMD1004=="PRT_2002"
replace gini=34.2 if IMD1004=="PRT_2005"
replace gini=33.6 if IMD1004=="PRT_2009"
replace gini=33.2 if IMD1004=="PRT_2015"
replace gini=27.6 if IMD1004=="ROU_1996"
replace gini=31.1 if IMD1004=="ROU_2004"
replace gini=32.9 if IMD1004=="ROU_2012"
replace gini=36.4 if IMD1004=="RUS_1999"
replace gini=33.9 if IMD1004=="SRB_2012"
replace gini=25.5 if IMD1004=="SVK_2010"
replace gini=23.6 if IMD1004=="SVK_2016"
replace gini=23.4 if IMD1004=="SVN_1996"
replace gini=23.6 if IMD1004=="SVN_2004"
replace gini=23.7 if IMD1004=="SVN_2008"
replace gini=25 if IMD1004=="SVN_2011"
replace gini=24.5 if IMD1004=="SWE_1998"
replace gini=24.3 if IMD1004=="SWE_2002"
replace gini=24.5 if IMD1004=="SWE_2006"
replace gini=26 if IMD1004=="SWE_2014"
replace gini=40.3 if IMD1004=="TUR_2011"
replace gini=40.1 if IMD1004=="TUR_2015"
replace gini=40.2 if IMD1004=="TUR_2018"
replace gini=29.7 if IMD1004=="UKR_1998"
replace gini=41.2 if IMD1004=="URY_2009"
replace gini=37.7 if IMD1004=="USA_2004"
replace gini=38 if IMD1004=="USA_2008"
replace gini=38.1 if IMD1004=="USA_2012"
replace gini=62.9 if IMD1004=="ZAF_2014"

*gdppc - GDP per capita 
gen gdppc=. 
label var gdppc "GDP per capita, PPP(curret int$ in 1,000s, World Bank)"
replace gdppc=5.86532 if IMD1004=="ALB_2005"
replace gdppc=20.1052 if IMD1004=="ARG_2015"
replace gdppc=21.95826 if IMD1004=="AUS_1996"
replace gdppc=31.30821 if IMD1004=="AUS_2004"
replace gdppc=36.54489 if IMD1004=="AUS_2007"
replace gdppc=45.90205 if IMD1004=="AUS_2013"
replace gdppc=41.31623 if IMD1004=="AUT_2008"
replace gdppc=47.92205 if IMD1004=="AUT_2013"
replace gdppc=54.34295 if IMD1004=="AUT_2017"
replace gdppc=25.44084 if IMD1004=="BELF1999"
replace gdppc=6.961973 if IMD1004=="BGR_2001"
replace gdppc=17.56138 if IMD1004=="BGR_2014"
replace gdppc=9.568064 if IMD1004=="BRA_2002"
replace gdppc=11.64244 if IMD1004=="BRA_2006"
replace gdppc=14.29955 if IMD1004=="BRA_2010"
replace gdppc=15.71856 if IMD1004=="BRA_2014"
replace gdppc=14.95181 if IMD1004=="BRA_2018"
replace gdppc=25.16687 if IMD1004=="CAN_1997"
replace gdppc=33.79566 if IMD1004=="CAN_2004"
replace gdppc=40.27599 if IMD1004=="CAN_2008"
replace gdppc=41.56945 if IMD1004=="CAN_2011"
replace gdppc=44.67008 if IMD1004=="CAN_2015"
replace gdppc=33.81408 if IMD1004=="CHE_1999"
replace gdppc=37.71629 if IMD1004=="CHE_2003"
replace gdppc=49.73403 if IMD1004=="CHE_2007"
replace gdppc=56.18383 if IMD1004=="CHE_2011"
replace gdppc=12.74658 if IMD1004=="CHL_2005"
replace gdppc=16.15961 if IMD1004=="CHL_2009"
replace gdppc=24.54819 if IMD1004=="CHL_2017"
replace gdppc=14.65362 if IMD1004=="CZE_1996"
replace gdppc=18.25257 if IMD1004=="CZE_2002"
replace gdppc=23.8917 if IMD1004=="CZE_2006"
replace gdppc=27.90326 if IMD1004=="CZE_2010"
replace gdppc=30.81811 if IMD1004=="CZE_2013"
replace gdppc=29.17864 if IMD1004=="DEU12002"
replace gdppc=29.17864 if IMD1004=="DEU22002"
replace gdppc=25.34405 if IMD1004=="DEU_1998"
replace gdppc=31.7941 if IMD1004=="DEU_2005"
replace gdppc=36.84292 if IMD1004=="DEU_2009"
replace gdppc=44.99389 if IMD1004=="DEU_2013"
replace gdppc=53.12199 if IMD1004=="DEU_2017"
replace gdppc=25.81301 if IMD1004=="DNK_1998"
replace gdppc=29.45004 if IMD1004=="DNK_2001"
replace gdppc=38.95886 if IMD1004=="DNK_2007"
replace gdppc=16.93803 if IMD1004=="ESP_1996"
replace gdppc=26.12197 if IMD1004=="ESP_2004"
replace gdppc=33.26328 if IMD1004=="ESP_2008"
replace gdppc=31.86797 if IMD1004=="EST_2011"
replace gdppc=29.02157 if IMD1004=="FIN_2003"
replace gdppc=37.79242 if IMD1004=="FIN_2007"
replace gdppc=40.91684 if IMD1004=="FIN_2011"
replace gdppc=42.4977 if IMD1004=="FIN_2015"
replace gdppc=34.07993 if IMD1004=="FRA_2007"
replace gdppc=23.03433 if IMD1004=="GBR_1997"
replace gdppc=32.66823 if IMD1004=="GBR_2005"
replace gdppc=42.50672 if IMD1004=="GBR_2015"
replace gdppc=30.38149 if IMD1004=="GRC_2009"
replace gdppc=25.28447 if IMD1004=="GRC_2012"
replace gdppc=26.89533 if IMD1004=="GRC_2015"
replace gdppc=19.31872 if IMD1004=="HRV_2007"
replace gdppc=10.39768 if IMD1004=="HUN_1998"
replace gdppc=14.52639 if IMD1004=="HUN_2002"
replace gdppc=32.83404 if IMD1004=="HUN_2018"
replace gdppc=35.21209 if IMD1004=="IRL_2002"
replace gdppc=46.74816 if IMD1004=="IRL_2007"
replace gdppc=44.85532 if IMD1004=="IRL_2011"
replace gdppc=71.92896 if IMD1004=="IRL_2016"
replace gdppc=29.52319 if IMD1004=="ISL_1999"
replace gdppc=32.62188 if IMD1004=="ISL_2003"
replace gdppc=41.15004 if IMD1004=="ISL_2007"
replace gdppc=41.92761 if IMD1004=="ISL_2009"
replace gdppc=44.15755 if IMD1004=="ISL_2013"
replace gdppc=20.7359 if IMD1004=="ISR_1996"
replace gdppc=23.81843 if IMD1004=="ISR_2003"
replace gdppc=25.68599 if IMD1004=="ISR_2006"
replace gdppc=34.14571 if IMD1004=="ISR_2013"
replace gdppc=32.41018 if IMD1004=="ITA_2006"
replace gdppc=44.47187 if IMD1004=="ITA_2018"
replace gdppc=2.767403 if IMD1004=="KEN_2013"
replace gdppc=18.53938 if IMD1004=="KOR_2000"
replace gdppc=23.76354 if IMD1004=="KOR_2004"
replace gdppc=29.94608 if IMD1004=="KOR_2008"
replace gdppc=39.57545 if IMD1004=="KOR_2016"
replace gdppc=30.92517 if IMD1004=="LTU_2016"
replace gdppc=19.8792 if IMD1004=="LVA_2011"
replace gdppc=23.80381 if IMD1004=="LVA_2014"
replace gdppc=9.71209 if IMD1004=="MEX_1997"
replace gdppc=11.08981 if IMD1004=="MEX_2000"
replace gdppc=11.48245 if IMD1004=="MEX_2003"
replace gdppc=13.80818 if IMD1004=="MEX_2006"
replace gdppc=14.55824 if IMD1004=="MEX_2009"
replace gdppc=17.16293 if IMD1004=="MEX_2012"
replace gdppc=18.3015 if IMD1004=="MEX_2015"
replace gdppc=13.86397 if IMD1004=="MNE_2012"
replace gdppc=18.19933 if IMD1004=="MNE_2016"
replace gdppc=27.70784 if IMD1004=="NLD_1998"
replace gdppc=34.44721 if IMD1004=="NLD_2002"
replace gdppc=40.95892 if IMD1004=="NLD_2006"
replace gdppc=45.07832 if IMD1004=="NLD_2010"
replace gdppc=37.78064 if IMD1004=="NOR_2001"
replace gdppc=47.79753 if IMD1004=="NOR_2005"
replace gdppc=55.40497 if IMD1004=="NOR_2009"
replace gdppc=66.96125 if IMD1004=="NOR_2013"
replace gdppc=64.25528 if IMD1004=="NOR_2017"
replace gdppc=18.46378 if IMD1004=="NZL_1996"
replace gdppc=23.30628 if IMD1004=="NZL_2002"
replace gdppc=29.86273 if IMD1004=="NZL_2008"
replace gdppc=32.7439 if IMD1004=="NZL_2011"
replace gdppc=37.27695 if IMD1004=="NZL_2014"
replace gdppc=42.27441 if IMD1004=="NZL_2017"
replace gdppc=7.262258 if IMD1004=="PER_2006"
replace gdppc=10.4768 if IMD1004=="PER_2011"
replace gdppc=12.01338 if IMD1004=="PER_2016"
replace gdppc=7.703754 if IMD1004=="PHL_2016"
replace gdppc=8.933514 if IMD1004=="POL_1997"
replace gdppc=11.12453 if IMD1004=="POL_2001"
replace gdppc=13.89679 if IMD1004=="POL_2005"
replace gdppc=16.78244 if IMD1004=="POL_2007"
replace gdppc=22.8277 if IMD1004=="POL_2011"
replace gdppc=20.35665 if IMD1004=="PRT_2002"
replace gdppc=22.72528 if IMD1004=="PRT_2005"
replace gdppc=26.47837 if IMD1004=="PRT_2009"
replace gdppc=29.6609 if IMD1004=="PRT_2015"
replace gdppc=5.73138 if IMD1004=="ROU_1996"
replace gdppc=8.982844 if IMD1004=="ROU_2004"
replace gdppc=18.86962 if IMD1004=="ROU_2012"
replace gdppc=5.914326 if IMD1004=="RUS_1999"
replace gdppc=13.93392 if IMD1004=="SRB_2012"
replace gdppc=25.20935 if IMD1004=="SVK_2010"
replace gdppc=29.65937 if IMD1004=="SVK_2016"
replace gdppc=14.27314 if IMD1004=="SVN_1996"
replace gdppc=22.74209 if IMD1004=="SVN_2004"
replace gdppc=29.60429 if IMD1004=="SVN_2008"
replace gdppc=28.93138 if IMD1004=="SVN_2011"
replace gdppc=25.88679 if IMD1004=="SWE_1998"
replace gdppc=30.92651 if IMD1004=="SWE_2002"
replace gdppc=37.6797 if IMD1004=="SWE_2006"
replace gdppc=47.18467 if IMD1004=="SWE_2014"
replace gdppc=19.79895 if IMD1004=="TUR_2011"
replace gdppc=25.75339 if IMD1004=="TUR_2015"
replace gdppc=28.83193 if IMD1004=="TUR_2018"
replace gdppc=3.674413 if IMD1004=="UKR_1998"
replace gdppc=15.46426 if IMD1004=="URY_2009"
replace gdppc=41.7128 if IMD1004=="USA_2004"
replace gdppc=48.38256 if IMD1004=="USA_2008"
replace gdppc=51.61061 if IMD1004=="USA_2012"
replace gdppc=12.52071 if IMD1004=="ZAF_2014"


*ADDITIONAL VARIABLES FOR THE ROBUSTNESS TESTS

*r_twopty_dif - Perceived distance between two largest parties (in terms of vote shares)
gen r_twopty_dif=.
replace r_twopty_dif=abs(IMD3007_A - IMD3007_B) if module<5
replace r_twopty_dif=abs(E3019_A - E3019_B) if module==5

label var r_twopty_dif "abs LR distance btw two largest parties(votes), respondent"
replace r_twopty_dif=0 if ((IMD3007_A==. & IMD3007_B!=.) & module<5)
replace r_twopty_dif=0 if ((IMD3007_A!=. & IMD3007_B==.) & module<5)
replace r_twopty_dif=0 if ((IMD3007_A==. & IMD3007_B==.) & module<5)

replace r_twopty_dif=0 if (E3019_A==. & E3019_B!=.)
replace r_twopty_dif=0 if (E3019_A!=. & E3019_B==.)
replace r_twopty_dif=0 if ((E3019_A==. & E3019_B==.) & module==5)

*e_twopty_dif - Distance between two largest parties (in terms of vote shares) based on expert party placements  
gen e_twopty_dif=. 
label var e_twopty_dif "abs LR distance btw two top parties(votes), expert"
replace e_twopty_dif=abs(IMD5012_A - IMD5012_B) if module<5
replace e_twopty_dif=abs(E5018_A - E5018_B) if module==5

*PID_str - Partisanship intensity 
gen PID_str14=.
replace PID_str14=0 if PID==0 
replace PID_str14=1 if (PID==1 & IMD3005_4==3)
replace PID_str14=2 if (PID==1 & IMD3005_4==2)
replace PID_str14=3 if (PID==1 & IMD3005_4==1)

gen PID_str5=.
replace PID_str5=0 if PID==0 
replace PID_str5=1 if (PID==1 & E3024_4==3)
replace PID_str5=2 if (PID==1 & E3024_4==2) 
replace PID_str5=3 if (PID==1 & E3024_4==1)

gen PID_str=.
replace PID_str=PID_str14 if module<5
replace PID_str=PID_str5 if module==5
drop PID_str14 PID_str5

*Country-elections dropped due to missing values on the partisanship intensity variable
*FIN_2015 IRL_2011 dropped because party closeness strenght is available only for non-partisans
replace PID_str=. if IMD1004=="BELF1999"
replace PID_str=. if IMD1004=="NZL_1996"
replace PID_str=. if IMD1004=="KEN_2013"
replace PID_str=. if IMD1004=="SVN_1996"
replace PID_str=. if IMD1004=="FIN_2015"
replace PID_str=. if IMD1004=="IRL_2011" 

label define PIDstr_label 0"not PID" 1"not very close PID" 2"somewhat close PID" 3"very close PID"
label values PID_str PIDstr_label
label var PID_str "Partisanship with strength"

*A combined measure of PID_full and PID_str
gen PIDstr_govpty=0
replace PIDstr_govpty=PID_str if PID_full==2
label var PIDstr_govpty "Governing party partisanship intensity"

gen PIDstr_ngovpty=0
replace PIDstr_ngovpty=PID_str if PID_full==1
label var PIDstr_ngovpty "Non-governing party partisanship intensity"

*Country-elections recoded into missing values because no data available on the partisanship intensity variable (PID_str) 
replace PIDstr_govpty=. if IMD1004=="BELF1999" 
replace PIDstr_govpty=. if IMD1004=="FIN_2015" 
replace PIDstr_govpty=. if IMD1004=="IRL_2011" 
replace PIDstr_govpty=. if IMD1004=="KEN_2013" 
replace PIDstr_govpty=. if IMD1004=="NZL_1996" 
replace PIDstr_govpty=. if IMD1004=="SVN_1996" 

replace PIDstr_ngovpty=. if IMD1004=="BELF1999" 
replace PIDstr_ngovpty=. if IMD1004=="FIN_2015" 
replace PIDstr_ngovpty=. if IMD1004=="IRL_2011" 
replace PIDstr_ngovpty=. if IMD1004=="KEN_2013" 
replace PIDstr_ngovpty=. if IMD1004=="NZL_1996" 
replace PIDstr_ngovpty=. if IMD1004=="SVN_1996" 

*Country-elections dropped from the sample because no data available on the partisanship (extended) variable (PID_full) 
*HUN_2002 was dropped because its variable coding was inconsistent with other countries
replace PIDstr_govpty=. if IMD1004=="KOR_2016" 
replace PIDstr_govpty=. if IMD1004=="IRL_2007" 
replace PIDstr_govpty=. if IMD1004=="HUN_2002" 
replace PIDstr_govpty=. if IMD1004=="CHL_2017" 
replace PIDstr_govpty=. if IMD1004=="CHL_2009" 

replace PIDstr_ngovpty=. if IMD1004=="KOR_2016" 
replace PIDstr_ngovpty=. if IMD1004=="IRL_2007" 
replace PIDstr_ngovpty=. if IMD1004=="HUN_2002" 
replace PIDstr_ngovpty=. if IMD1004=="CHL_2017" 
replace PIDstr_ngovpty=. if IMD1004=="CHL_2009" 

*FH - Freedom House 
gen FH=.
replace FH=IMD5050_1 if module<5
replace FH=E5090_1 if module==5
recode FH 9=.
label var FH "Freedom House Political Rights score"
*Freedom House value was missing for HUN_2018
replace FH=3 if IMD1004=="HUN_2018" 

*% Partisans
gen prc_PID=.
label var prc_PID "% of partisans in country-election"
replace prc_PID=60.06 if IMD1004=="ALB_2005"
replace prc_PID=41.98 if IMD1004=="ARG_2015"
replace prc_PID=83.50 if IMD1004=="AUS_1996"
replace prc_PID=83.89 if IMD1004=="AUS_2004"
replace prc_PID=84.48 if IMD1004=="AUS_2007"
replace prc_PID=87.39 if IMD1004=="AUS_2013"
replace prc_PID=49.65 if IMD1004=="AUT_2008"
replace prc_PID=36.64 if IMD1004=="AUT_2013"
replace prc_PID=48.74 if IMD1004=="AUT_2017"
replace prc_PID=94.90 if IMD1004=="BELF1999"
replace prc_PID=42.71 if IMD1004=="BGR_2001"
replace prc_PID=36.70 if IMD1004=="BGR_2014"
replace prc_PID=49.35 if IMD1004=="BRA_2002"
replace prc_PID=33.40 if IMD1004=="BRA_2006"
replace prc_PID=47.99 if IMD1004=="BRA_2010"
replace prc_PID=27.26 if IMD1004=="BRA_2014"
replace prc_PID=15.98 if IMD1004=="BRA_2018"
replace prc_PID=52.12 if IMD1004=="CAN_1997"
replace prc_PID=38.53 if IMD1004=="CAN_2004"
replace prc_PID=40.17 if IMD1004=="CAN_2008"
replace prc_PID=47.65 if IMD1004=="CAN_2011"
replace prc_PID=48.93 if IMD1004=="CAN_2015"
replace prc_PID=36.74 if IMD1004=="CHE_1999"
replace prc_PID=44.90 if IMD1004=="CHE_2003"
replace prc_PID=40.35 if IMD1004=="CHE_2007"
replace prc_PID=39.94 if IMD1004=="CHE_2011"
replace prc_PID=35.14 if IMD1004=="CHL_2005"
replace prc_PID=26.25 if IMD1004=="CHL_2009"
replace prc_PID=13.74 if IMD1004=="CHL_2017"
replace prc_PID=48.80 if IMD1004=="CZE_1996"
replace prc_PID=63.69 if IMD1004=="CZE_2002"
replace prc_PID=44.16 if IMD1004=="CZE_2006"
replace prc_PID=39.78 if IMD1004=="CZE_2010"
replace prc_PID=32.17 if IMD1004=="CZE_2013"
replace prc_PID=37.70 if IMD1004=="DEU12002"
replace prc_PID=49.40 if IMD1004=="DEU22002"
replace prc_PID=37.36 if IMD1004=="DEU_1998"
replace prc_PID=44.80 if IMD1004=="DEU_2005"
replace prc_PID=49.08 if IMD1004=="DEU_2009"
replace prc_PID=48.47 if IMD1004=="DEU_2013"
replace prc_PID=40.69 if IMD1004=="DEU_2017"
replace prc_PID=51.36 if IMD1004=="DNK_1998"
replace prc_PID=50 if IMD1004=="DNK_2001"
replace prc_PID=56.25 if IMD1004=="DNK_2007"
replace prc_PID=43.54 if IMD1004=="ESP_1996"
replace prc_PID=61.30 if IMD1004=="ESP_2004"
replace prc_PID=62.71 if IMD1004=="ESP_2008"
replace prc_PID=40.17 if IMD1004=="EST_2011"
replace prc_PID=46.59 if IMD1004=="FIN_2003"
replace prc_PID=55.36 if IMD1004=="FIN_2007"
replace prc_PID=55.09 if IMD1004=="FIN_2011"
replace prc_PID=48.99 if IMD1004=="FIN_2015"
replace prc_PID=71.09 if IMD1004=="FRA_2007"
replace prc_PID=48.79 if IMD1004=="GBR_1997"
replace prc_PID=35.40 if IMD1004=="GBR_2005"
replace prc_PID=51.21 if IMD1004=="GBR_2015"
replace prc_PID=61.32 if IMD1004=="GRC_2009"
replace prc_PID=37.52 if IMD1004=="GRC_2012"
replace prc_PID=33.81 if IMD1004=="GRC_2015"
replace prc_PID=41.18 if IMD1004=="HRV_2007"
replace prc_PID=35.79 if IMD1004=="HUN_1998"
replace prc_PID=52.64 if IMD1004=="HUN_2002"
replace prc_PID=34.20 if IMD1004=="HUN_2018"
replace prc_PID=28.88 if IMD1004=="IRL_2002"
replace prc_PID=31.36 if IMD1004=="IRL_2007"
replace prc_PID=21.34 if IMD1004=="IRL_2011"
replace prc_PID=30.63 if IMD1004=="IRL_2016"
replace prc_PID=51.62 if IMD1004=="ISL_1999"
replace prc_PID=54.17 if IMD1004=="ISL_2003"
replace prc_PID=49.78 if IMD1004=="ISL_2007"
replace prc_PID=50.90 if IMD1004=="ISL_2009"
replace prc_PID=45.67 if IMD1004=="ISL_2013"
replace prc_PID=64.16 if IMD1004=="ISR_1996"
replace prc_PID=62.35 if IMD1004=="ISR_2003"
replace prc_PID=45.39 if IMD1004=="ISR_2006"
replace prc_PID=40.52 if IMD1004=="ISR_2013"
replace prc_PID=43.28 if IMD1004=="ITA_2006"
replace prc_PID=42.94 if IMD1004=="ITA_2018"
replace prc_PID=71.13 if IMD1004=="KEN_2013"
replace prc_PID=27.32 if IMD1004=="KOR_2000"
replace prc_PID=40.03 if IMD1004=="KOR_2004"
replace prc_PID=40.51 if IMD1004=="KOR_2008"
replace prc_PID=49.79 if IMD1004=="KOR_2016"
replace prc_PID=24.98 if IMD1004=="LTU_2016"
replace prc_PID=44.86 if IMD1004=="LVA_2011"
replace prc_PID=53.43 if IMD1004=="LVA_2014"
replace prc_PID=44.75 if IMD1004=="MEX_1997"
replace prc_PID=52.30 if IMD1004=="MEX_2000"
replace prc_PID=51.93 if IMD1004=="MEX_2003"
replace prc_PID=56.87 if IMD1004=="MEX_2006"
replace prc_PID=56.55 if IMD1004=="MEX_2009"
replace prc_PID=44.81 if IMD1004=="MEX_2012"
replace prc_PID=48.01 if IMD1004=="MEX_2015"
replace prc_PID=46.94 if IMD1004=="MNE_2012"
replace prc_PID=38.31 if IMD1004=="MNE_2016"
replace prc_PID=27.87 if IMD1004=="NLD_1998"
replace prc_PID=39.45 if IMD1004=="NLD_2002"
replace prc_PID=31.52 if IMD1004=="NLD_2006"
replace prc_PID=29.61 if IMD1004=="NLD_2010"
replace prc_PID=41.27 if IMD1004=="NOR_2001"
replace prc_PID=47.81 if IMD1004=="NOR_2005"
replace prc_PID=52.63 if IMD1004=="NOR_2009"
replace prc_PID=48.42 if IMD1004=="NOR_2013"
replace prc_PID=67.90 if IMD1004=="NOR_2017"
replace prc_PID=56.25 if IMD1004=="NZL_1996"
replace prc_PID=54.99 if IMD1004=="NZL_2002"
replace prc_PID=48.16 if IMD1004=="NZL_2008"
replace prc_PID=57 if IMD1004=="NZL_2011"
replace prc_PID=54.29 if IMD1004=="NZL_2014"
replace prc_PID=60.18 if IMD1004=="NZL_2017"
replace prc_PID=39.46 if IMD1004=="PER_2006"
replace prc_PID=49.05 if IMD1004=="PER_2011"
replace prc_PID=37.50 if IMD1004=="PER_2016"
replace prc_PID=17.92 if IMD1004=="PHL_2016"
replace prc_PID=53.72 if IMD1004=="POL_1997"
replace prc_PID=41.76 if IMD1004=="POL_2001"
replace prc_PID=50.75 if IMD1004=="POL_2005"
replace prc_PID=52.82 if IMD1004=="POL_2007"
replace prc_PID=36.81 if IMD1004=="POL_2011"
replace prc_PID=51.85 if IMD1004=="PRT_2002"
replace prc_PID=44.87 if IMD1004=="PRT_2005"
replace prc_PID=45.29 if IMD1004=="PRT_2009"
replace prc_PID=42 if IMD1004=="PRT_2015"
replace prc_PID=47.09 if IMD1004=="ROU_1996"
replace prc_PID=99.86 if IMD1004=="ROU_2004"
replace prc_PID=30.60 if IMD1004=="ROU_2012"
replace prc_PID=62.57 if IMD1004=="RUS_1999"
replace prc_PID=29.03 if IMD1004=="SRB_2012"
replace prc_PID=71.82 if IMD1004=="SVK_2010"
replace prc_PID=49.75 if IMD1004=="SVK_2016"
replace prc_PID=21.70 if IMD1004=="SVN_1996"
replace prc_PID=21.27 if IMD1004=="SVN_2004"
replace prc_PID=21.69 if IMD1004=="SVN_2008"
replace prc_PID=14.33 if IMD1004=="SVN_2011"
replace prc_PID=53.15 if IMD1004=="SWE_1998"
replace prc_PID=48.81 if IMD1004=="SWE_2002"
replace prc_PID=49.51 if IMD1004=="SWE_2006"
replace prc_PID=52.12 if IMD1004=="SWE_2014"
replace prc_PID=73.97 if IMD1004=="TUR_2011"
replace prc_PID=74.44 if IMD1004=="TUR_2015"
replace prc_PID=66.25 if IMD1004=="TUR_2018"
replace prc_PID=70.54 if IMD1004=="UKR_1998"
replace prc_PID=80.04 if IMD1004=="URY_2009"
replace prc_PID=56.83 if IMD1004=="USA_2004"
replace prc_PID=63.05 if IMD1004=="USA_2008"
replace prc_PID=60.79 if IMD1004=="USA_2012"
replace prc_PID=64 if IMD1004=="ZAF_2014"

*voted
gen voted=.
replace voted=1 if (IMD3001_LH==1 & module<5)
replace voted=0 if (IMD3001_LH==0 & module<5)
replace voted=1 if (E3012_LH==1 & module==5)
replace voted=0 if (E3012_LH==0 & module==5)

label var voted "voted in the last lower housed elections 1'yes' 0'no'"
label values voted voted_label

*race_maj - Majority race
gen race_maj=0
label var race_maj "Respondent belongs to the majority racial group in R's country"
label define racemaj_label 0"otherwise" 1"majority race" 
label values race_maj racemaj_label

replace race_maj=. if IMD1004=="ALB_2005"
replace race_maj=. if IMD1004=="ARG_2015"
replace race_maj=. if IMD1004=="AUS_1996"
replace race_maj=. if IMD1004=="AUS_2004"
replace race_maj=. if IMD1004=="AUS_2007"
replace race_maj=. if IMD1004=="AUS_2013"
replace race_maj=. if IMD1004=="AUT_2008"
replace race_maj=. if IMD1004=="AUT_2013"
replace race_maj=. if IMD1004=="AUT_2017"
replace race_maj=. if IMD1004=="BELF1999"
replace race_maj=. if IMD1004=="BGR_2001"
replace race_maj=. if IMD1004=="BGR_2014"
replace race_maj=1 if (IMD1004=="BRA_2002" & IMD2010==1)
replace race_maj=. if IMD1004=="BRA_2006"
replace race_maj=1 if (IMD1004=="BRA_2010" & IMD2010==1)
replace race_maj=1 if (IMD1004=="BRA_2014" & IMD2010==1)
replace race_maj=1 if (IMD1004=="BRA_2018" & E2015==2)
replace race_maj=. if IMD1004=="CAN_1997"
replace race_maj=. if IMD1004=="CAN_2004"
replace race_maj=. if IMD1004=="CAN_2008"
replace race_maj=. if IMD1004=="CAN_2011"
replace race_maj=. if IMD1004=="CAN_2015"
replace race_maj=. if IMD1004=="CHE_1999"
replace race_maj=. if IMD1004=="CHE_2003"
replace race_maj=. if IMD1004=="CHE_2007"
replace race_maj=. if IMD1004=="CHE_2011"
replace race_maj=. if IMD1004=="CHL_2005"
replace race_maj=. if IMD1004=="CHL_2009"
replace race_maj=. if IMD1004=="CHL_2017"
replace race_maj=. if IMD1004=="CZE_1996"
replace race_maj=. if IMD1004=="CZE_2002"
replace race_maj=. if IMD1004=="CZE_2006"
replace race_maj=. if IMD1004=="CZE_2010"
replace race_maj=. if IMD1004=="CZE_2013"
replace race_maj=. if IMD1004=="DEU12002"
replace race_maj=. if IMD1004=="DEU22002"
replace race_maj=. if IMD1004=="DEU_1998"
replace race_maj=. if IMD1004=="DEU_2005"
replace race_maj=. if IMD1004=="DEU_2009"
replace race_maj=. if IMD1004=="DEU_2013"
replace race_maj=. if IMD1004=="DEU_2017"
replace race_maj=. if IMD1004=="DNK_1998"
replace race_maj=. if IMD1004=="DNK_2001"
replace race_maj=. if IMD1004=="DNK_2007"
replace race_maj=. if IMD1004=="ESP_1996"
replace race_maj=. if IMD1004=="ESP_2004"
replace race_maj=. if IMD1004=="ESP_2008"
replace race_maj=. if IMD1004=="EST_2011"
replace race_maj=. if IMD1004=="FIN_2003"
replace race_maj=. if IMD1004=="FIN_2007"
replace race_maj=. if IMD1004=="FIN_2011"
replace race_maj=. if IMD1004=="FIN_2015"
replace race_maj=. if IMD1004=="FRA_2007"
replace race_maj=1 if (IMD1004=="GBR_1997" & IMD2010==1)
replace race_maj=1 if (IMD1004=="GBR_2005" & IMD2010==1)
replace race_maj=. if IMD1004=="GBR_2015"
replace race_maj=. if IMD1004=="GRC_2009"
replace race_maj=. if IMD1004=="GRC_2012"
replace race_maj=. if IMD1004=="GRC_2015"
replace race_maj=. if IMD1004=="HRV_2007"
replace race_maj=. if IMD1004=="HUN_1998"
replace race_maj=. if IMD1004=="HUN_2002"
replace race_maj=. if IMD1004=="HUN_2018"
replace race_maj=. if IMD1004=="IRL_2002"
replace race_maj=. if IMD1004=="IRL_2007"
replace race_maj=. if IMD1004=="IRL_2011"
replace race_maj=. if IMD1004=="IRL_2016"
replace race_maj=. if IMD1004=="ISL_1999"
replace race_maj=. if IMD1004=="ISL_2003"
replace race_maj=. if IMD1004=="ISL_2007"
replace race_maj=. if IMD1004=="ISL_2009"
replace race_maj=. if IMD1004=="ISL_2013"
replace race_maj=. if IMD1004=="ISR_1996"
replace race_maj=. if IMD1004=="ISR_2003"
replace race_maj=. if IMD1004=="ISR_2006"
replace race_maj=. if IMD1004=="ISR_2013"
replace race_maj=. if IMD1004=="ITA_2006"
replace race_maj=. if IMD1004=="ITA_2018"
replace race_maj=. if IMD1004=="KEN_2013"
replace race_maj=1 if (IMD1004=="KOR_2000" & & IMD2010==2)
replace race_maj=. if IMD1004=="KOR_2004"
replace race_maj=. if IMD1004=="KOR_2008"
replace race_maj=. if IMD1004=="KOR_2016"
replace race_maj=1 if (IMD1004=="LTU_2016" & E2015==1)
replace race_maj=. if IMD1004=="LVA_2011"
replace race_maj=. if IMD1004=="LVA_2014"
replace race_maj=1 if (IMD1004=="MEX_1997" & IMD2010==6)
replace race_maj=1 if (IMD1004=="MEX_2000" & IMD2010==6)
replace race_maj=1 if (IMD1004=="MEX_2003" & IMD2010==6)
replace race_maj=1 if (IMD1004=="MEX_2006" & IMD2010==6)
replace race_maj=1 if (IMD1004=="MEX_2009" & IMD2010==6)
replace race_maj=1 if (IMD1004=="MEX_2012" & IMD2010==6)
replace race_maj=1 if (IMD1004=="MEX_2015" & IMD2010==6)
replace race_maj=1 if (IMD1004=="MNE_2012" & IMD2010==1)
replace race_maj=1 if (IMD1004=="MNE_2016" & E2015==1)
replace race_maj=. if IMD1004=="NLD_1998"
replace race_maj=. if IMD1004=="NLD_2002"
replace race_maj=. if IMD1004=="NLD_2006"
replace race_maj=. if IMD1004=="NLD_2010"
replace race_maj=. if IMD1004=="NOR_2001"
replace race_maj=. if IMD1004=="NOR_2005"
replace race_maj=. if IMD1004=="NOR_2009"
replace race_maj=. if IMD1004=="NOR_2013"
replace race_maj=. if IMD1004=="NOR_2017"
replace race_maj=. if IMD1004=="NZL_1996"
replace race_maj=. if IMD1004=="NZL_2002"
replace race_maj=1 if (IMD1004=="NZL_2008" & IMD2010==96)
replace race_maj=. if IMD1004=="NZL_2011"
replace race_maj=. if IMD1004=="NZL_2014"
replace race_maj=1 if (IMD1004=="NZL_2017" & E2015==2)
replace race_maj=. if IMD1004=="PER_2006"
replace race_maj=1 if (IMD1004=="PER_2011" & IMD2010==6)
replace race_maj=1 if (IMD1004=="PER_2016" & IMD2010==6)
replace race_maj=1 if (IMD1004=="PHL_2016" & IMD2010==2)
replace race_maj=. if IMD1004=="POL_1997"
replace race_maj=. if IMD1004=="POL_2001"
replace race_maj=. if IMD1004=="POL_2005"
replace race_maj=. if IMD1004=="POL_2007"
replace race_maj=. if IMD1004=="POL_2011"
replace race_maj=1 if (IMD1004=="PRT_2002" & IMD2010==1)
replace race_maj=1 if (IMD1004=="PRT_2005" & IMD2010==1)
replace race_maj=1 if (IMD1004=="PRT_2009" & IMD2010==1)
replace race_maj=1 if (IMD1004=="PRT_2015" & IMD2010==1)
replace race_maj=. if IMD1004=="ROU_1996"
replace race_maj=. if IMD1004=="ROU_2004"
replace race_maj=1 if (IMD1004=="ROU_2012" & IMD2010==1)
replace race_maj=. if IMD1004=="RUS_1999"
replace race_maj=. if IMD1004=="SRB_2012"
replace race_maj=. if IMD1004=="SVK_2010"
replace race_maj=. if IMD1004=="SVK_2016"
replace race_maj=. if IMD1004=="SVN_1996"
replace race_maj=. if IMD1004=="SVN_2004"
replace race_maj=. if IMD1004=="SVN_2008"
replace race_maj=. if IMD1004=="SVN_2011"
replace race_maj=. if IMD1004=="SWE_1998"
replace race_maj=. if IMD1004=="SWE_2002"
replace race_maj=. if IMD1004=="SWE_2006"
replace race_maj=. if IMD1004=="SWE_2014"
replace race_maj=. if IMD1004=="TUR_2011"
replace race_maj=. if IMD1004=="TUR_2015"
replace race_maj=. if IMD1004=="TUR_2018"
replace race_maj=1 if (IMD1004=="UKR_1998" & IMD2010==1)
replace race_maj=1 if (IMD1004=="URY_2009" & IMD2010==1)
replace race_maj=1 if (IMD1004=="USA_2004" & IMD2010==1)
replace race_maj=1 if (IMD1004=="USA_2008" & IMD2010==1)
replace race_maj=1 if (IMD1004=="USA_2012" & IMD2010==1)
replace race_maj=1 if (IMD1004=="ZAF_2014" & IMD2010==3)


*n_el1 - cumulative number of legislative elections (including current election) since 1990
gen n_el=.
label var n_el "nr of legislative elections since 1900, V-Dem data"
replace n_el=31 if IMD1004=="ALB_2005"
replace n_el=44 if IMD1004=="ARG_2015"
replace n_el=38 if IMD1004=="AUS_1996"
replace n_el=41 if IMD1004=="AUS_2004"
replace n_el=42 if IMD1004=="AUS_2007"
replace n_el=44 if IMD1004=="AUS_2013"
replace n_el=27 if IMD1004=="AUT_2008"
replace n_el=28 if IMD1004=="AUT_2013"
replace n_el=29 if IMD1004=="AUT_2017"
replace n_el=33 if IMD1004=="BELF1999"
replace n_el=32 if IMD1004=="BGR_2001"
replace n_el=36 if IMD1004=="BGR_2014"
replace n_el=24 if IMD1004=="BRA_2002"
replace n_el=25 if IMD1004=="BRA_2006"
replace n_el=26 if IMD1004=="BRA_2010"
replace n_el=27 if IMD1004=="BRA_2014"
replace n_el=28 if IMD1004=="BRA_2018"
replace n_el=28 if IMD1004=="CAN_1997"
replace n_el=30 if IMD1004=="CAN_2004"
replace n_el=32 if IMD1004=="CAN_2008"
replace n_el=33 if IMD1004=="CAN_2011"
replace n_el=34 if IMD1004=="CAN_2015"
replace n_el=28 if IMD1004=="CHE_1999"
replace n_el=29 if IMD1004=="CHE_2003"
replace n_el=30 if IMD1004=="CHE_2007"
replace n_el=31 if IMD1004=="CHE_2011"
replace n_el=27 if IMD1004=="CHL_2005"
replace n_el=28 if IMD1004=="CHL_2009"
replace n_el=30 if IMD1004=="CHL_2017"
replace n_el=16 if IMD1004=="CZE_1996"
replace n_el=18 if IMD1004=="CZE_2002"
replace n_el=19 if IMD1004=="CZE_2006"
replace n_el=20 if IMD1004=="CZE_2010"
replace n_el=21 if IMD1004=="CZE_2013"
replace n_el=29 if IMD1004=="DEU12002"
replace n_el=29 if IMD1004=="DEU22002"
replace n_el=28 if IMD1004=="DEU_1998"
replace n_el=30 if IMD1004=="DEU_2005"
replace n_el=31 if IMD1004=="DEU_2009"
replace n_el=32 if IMD1004=="DEU_2013"
replace n_el=33 if IMD1004=="DEU_2017"
replace n_el=40 if IMD1004=="DNK_1998"
replace n_el=41 if IMD1004=="DNK_2001"
replace n_el=43 if IMD1004=="DNK_2007"
replace n_el=23 if IMD1004=="ESP_1996"
replace n_el=25 if IMD1004=="ESP_2004"
replace n_el=26 if IMD1004=="ESP_2008"
replace n_el=13 if IMD1004=="EST_2011"
replace n_el=37 if IMD1004=="FIN_2003"
replace n_el=38 if IMD1004=="FIN_2007"
replace n_el=39 if IMD1004=="FIN_2011"
replace n_el=40 if IMD1004=="FIN_2015"
replace n_el=46 if IMD1004=="FRA_2007"
replace n_el=26 if IMD1004=="GBR_1997"
replace n_el=28 if IMD1004=="GBR_2005"
replace n_el=30 if IMD1004=="GBR_2015"
replace n_el=38 if IMD1004=="GRC_2009"
replace n_el=40 if IMD1004=="GRC_2012"
replace n_el=42 if IMD1004=="GRC_2015"
replace n_el=5 if IMD1004=="HRV_2007"
replace n_el=27 if IMD1004=="HUN_1998"
replace n_el=29 if IMD1004=="HUN_2002"
replace n_el=35 if IMD1004=="HUN_2018"
replace n_el=27 if IMD1004=="IRL_2002"
replace n_el=28 if IMD1004=="IRL_2007"
replace n_el=29 if IMD1004=="IRL_2011"
replace n_el=30 if IMD1004=="IRL_2016"
replace n_el=33 if IMD1004=="ISL_1999"
replace n_el=34 if IMD1004=="ISL_2003"
replace n_el=35 if IMD1004=="ISL_2007"
replace n_el=36 if IMD1004=="ISL_2009"
replace n_el=37 if IMD1004=="ISL_2013"
replace n_el=14 if IMD1004=="ISR_1996"
replace n_el=16 if IMD1004=="ISR_2003"
replace n_el=17 if IMD1004=="ISR_2006"
replace n_el=19 if IMD1004=="ISR_2013"
replace n_el=29 if IMD1004=="ITA_2006"
replace n_el=32 if IMD1004=="ITA_2018"
replace n_el=25 if IMD1004=="KEN_2013"
replace n_el=16 if IMD1004=="KOR_2000"
replace n_el=17 if IMD1004=="KOR_2004"
replace n_el=18 if IMD1004=="KOR_2008"
replace n_el=20 if IMD1004=="KOR_2016"
replace n_el=19 if IMD1004=="LTU_2016"
replace n_el=12 if IMD1004=="LVA_2011"
replace n_el=13 if IMD1004=="LVA_2014"
replace n_el=21 if IMD1004=="MEX_1997"
replace n_el=22 if IMD1004=="MEX_2000"
replace n_el=23 if IMD1004=="MEX_2003"
replace n_el=24 if IMD1004=="MEX_2006"
replace n_el=25 if IMD1004=="MEX_2009"
replace n_el=26 if IMD1004=="MEX_2012"
replace n_el=27 if IMD1004=="MEX_2015"
replace n_el=11 if IMD1004=="MNE_2012"
replace n_el=12 if IMD1004=="MNE_2016"
replace n_el=32 if IMD1004=="NLD_1998"
replace n_el=33 if IMD1004=="NLD_2002"
replace n_el=35 if IMD1004=="NLD_2006"
replace n_el=36 if IMD1004=="NLD_2010"
replace n_el=33 if IMD1004=="NOR_2001"
replace n_el=34 if IMD1004=="NOR_2005"
replace n_el=35 if IMD1004=="NOR_2009"
replace n_el=36 if IMD1004=="NOR_2013"
replace n_el=37 if IMD1004=="NOR_2017"
replace n_el=33 if IMD1004=="NZL_1996"
replace n_el=35 if IMD1004=="NZL_2002"
replace n_el=37 if IMD1004=="NZL_2008"
replace n_el=38 if IMD1004=="NZL_2011"
replace n_el=39 if IMD1004=="NZL_2014"
replace n_el=40 if IMD1004=="NZL_2017"
replace n_el=16 if IMD1004=="PER_2006"
replace n_el=17 if IMD1004=="PER_2011"
replace n_el=18 if IMD1004=="PER_2016"
replace n_el=34 if IMD1004=="PHL_2016"
replace n_el=21 if IMD1004=="POL_1997"
replace n_el=22 if IMD1004=="POL_2001"
replace n_el=23 if IMD1004=="POL_2005"
replace n_el=24 if IMD1004=="POL_2007"
replace n_el=25 if IMD1004=="POL_2011"
replace n_el=34 if IMD1004=="PRT_2002"
replace n_el=35 if IMD1004=="PRT_2005"
replace n_el=36 if IMD1004=="PRT_2009"
replace n_el=38 if IMD1004=="PRT_2015"
replace n_el=32 if IMD1004=="ROU_1996"
replace n_el=34 if IMD1004=="ROU_2004"
replace n_el=36 if IMD1004=="ROU_2012"
replace n_el=16 if IMD1004=="RUS_1999"
replace n_el=24 if IMD1004=="SRB_2012"
replace n_el=5 if IMD1004=="SVK_2010"
replace n_el=7 if IMD1004=="SVK_2016"
replace n_el=3 if IMD1004=="SVN_1996"
replace n_el=5 if IMD1004=="SVN_2004"
replace n_el=6 if IMD1004=="SVN_2008"
replace n_el=7 if IMD1004=="SVN_2011"
replace n_el=32 if IMD1004=="SWE_1998"
replace n_el=33 if IMD1004=="SWE_2002"
replace n_el=34 if IMD1004=="SWE_2006"
replace n_el=36 if IMD1004=="SWE_2014"
replace n_el=33 if IMD1004=="TUR_2011"
replace n_el=35 if IMD1004=="TUR_2015"
replace n_el=36 if IMD1004=="TUR_2018"
replace n_el=5 if IMD1004=="UKR_1998"
replace n_el=27 if IMD1004=="URY_2009"
replace n_el=53 if IMD1004=="USA_2004"
replace n_el=55 if IMD1004=="USA_2008"
replace n_el=57 if IMD1004=="USA_2012"
replace n_el=25 if IMD1004=="ZAF_2014"

gen cons_dem=.
label var cons_dem "Lijphart's majoritarian vs. consensus democracy"

*Clear cases 
*Consensus democracies 
replace cons_dem=1 if IMD1004=="AUT_2008"
replace cons_dem=1 if IMD1004=="AUT_2013"
replace cons_dem=1 if IMD1004=="AUT_2017"
replace cons_dem=1 if IMD1004=="BELF1999"
replace cons_dem=1 if IMD1004=="BRA_2002"
replace cons_dem=1 if IMD1004=="BRA_2006"
replace cons_dem=1 if IMD1004=="BRA_2010"
replace cons_dem=1 if IMD1004=="BRA_2014"
replace cons_dem=1 if IMD1004=="BRA_2018"
replace cons_dem=1 if IMD1004=="CHE_1999"
replace cons_dem=1 if IMD1004=="CHE_2003"
replace cons_dem=1 if IMD1004=="CHE_2007"
replace cons_dem=1 if IMD1004=="CHE_2011"
replace cons_dem=1 if IMD1004=="CZE_1996"
replace cons_dem=1 if IMD1004=="CZE_2002"
replace cons_dem=1 if IMD1004=="CZE_2006"
replace cons_dem=1 if IMD1004=="CZE_2010"
replace cons_dem=1 if IMD1004=="CZE_2013"
replace cons_dem=1 if IMD1004=="DNK_1998"
replace cons_dem=1 if IMD1004=="DNK_2001"
replace cons_dem=1 if IMD1004=="DNK_2007"
replace cons_dem=1 if IMD1004=="EST_2011"
replace cons_dem=1 if IMD1004=="FIN_2003"
replace cons_dem=1 if IMD1004=="FIN_2007"
replace cons_dem=1 if IMD1004=="FIN_2011"
replace cons_dem=1 if IMD1004=="FIN_2015"
replace cons_dem=1 if IMD1004=="ISR_1996"
replace cons_dem=1 if IMD1004=="ISR_2003"
replace cons_dem=1 if IMD1004=="ISR_2006"
replace cons_dem=1 if IMD1004=="ISR_2013"
replace cons_dem=1 if IMD1004=="ITA_2006"
replace cons_dem=1 if IMD1004=="ITA_2018"
replace cons_dem=1 if IMD1004=="LVA_2011"
replace cons_dem=1 if IMD1004=="LVA_2014"
replace cons_dem=1 if IMD1004=="NLD_1998"
replace cons_dem=1 if IMD1004=="NLD_2002"
replace cons_dem=1 if IMD1004=="NLD_2006"
replace cons_dem=1 if IMD1004=="NLD_2010"
replace cons_dem=1 if IMD1004=="NOR_2001"
replace cons_dem=1 if IMD1004=="NOR_2005"
replace cons_dem=1 if IMD1004=="NOR_2009"
replace cons_dem=1 if IMD1004=="NOR_2013"
replace cons_dem=1 if IMD1004=="NOR_2017"
replace cons_dem=1 if IMD1004=="POL_1997"
replace cons_dem=1 if IMD1004=="POL_2001"
replace cons_dem=1 if IMD1004=="POL_2005"
replace cons_dem=1 if IMD1004=="POL_2007"
replace cons_dem=1 if IMD1004=="POL_2011"
replace cons_dem=1 if IMD1004=="PRT_2002"
replace cons_dem=1 if IMD1004=="ROU_1996"
replace cons_dem=1 if IMD1004=="ROU_2004"
replace cons_dem=1 if IMD1004=="ROU_2012"
replace cons_dem=1 if IMD1004=="SRB_2012"
replace cons_dem=1 if IMD1004=="SVK_2010"
replace cons_dem=1 if IMD1004=="SVK_2016"
replace cons_dem=1 if IMD1004=="SVN_1996"
replace cons_dem=1 if IMD1004=="SVN_2004"
replace cons_dem=1 if IMD1004=="SVN_2008"
replace cons_dem=1 if IMD1004=="SVN_2011"
replace cons_dem=1 if IMD1004=="SWE_1998"
replace cons_dem=1 if IMD1004=="SWE_2002"
replace cons_dem=1 if IMD1004=="SWE_2006"
replace cons_dem=1 if IMD1004=="SWE_2014"
replace cons_dem=1 if IMD1004=="URY_2009"


*Majoritarian democracies 
replace cons_dem=0 if IMD1004=="ARG_2015"
replace cons_dem=0 if IMD1004=="ALB_2005"
replace cons_dem=0 if IMD1004=="AUS_1996"
replace cons_dem=0 if IMD1004=="AUS_2004"
replace cons_dem=0 if IMD1004=="AUS_2007"
replace cons_dem=0 if IMD1004=="AUS_2013"
replace cons_dem=0 if IMD1004=="BGR_2001"
replace cons_dem=0 if IMD1004=="BGR_2014"
replace cons_dem=0 if IMD1004=="CAN_1997"
replace cons_dem=0 if IMD1004=="CAN_2004"
replace cons_dem=0 if IMD1004=="CAN_2008"
replace cons_dem=0 if IMD1004=="CAN_2011"
replace cons_dem=0 if IMD1004=="CAN_2015"
replace cons_dem=0 if IMD1004=="CHL_2005"
replace cons_dem=0 if IMD1004=="CHL_2009"
replace cons_dem=0 if IMD1004=="CHL_2017"
replace cons_dem=0 if IMD1004=="DEU12002"
replace cons_dem=0 if IMD1004=="DEU22002"
replace cons_dem=0 if IMD1004=="DEU_1998"
replace cons_dem=0 if IMD1004=="DEU_2005"
replace cons_dem=0 if IMD1004=="DEU_2009"
replace cons_dem=0 if IMD1004=="DEU_2013"
replace cons_dem=0 if IMD1004=="DEU_2017"
replace cons_dem=0 if IMD1004=="ESP_1996"
replace cons_dem=0 if IMD1004=="ESP_2004"
replace cons_dem=0 if IMD1004=="ESP_2008"
replace cons_dem=0 if IMD1004=="FRA_2007"
replace cons_dem=0 if IMD1004=="GBR_1997"
replace cons_dem=0 if IMD1004=="GBR_2005"
replace cons_dem=0 if IMD1004=="GBR_2015"
replace cons_dem=0 if IMD1004=="GRC_2009"
replace cons_dem=0 if IMD1004=="GRC_2012"
replace cons_dem=0 if IMD1004=="GRC_2015"
replace cons_dem=0 if IMD1004=="HRV_2007"
replace cons_dem=0 if IMD1004=="HUN_1998"
replace cons_dem=0 if IMD1004=="HUN_2002"
replace cons_dem=0 if IMD1004=="HUN_2018"
replace cons_dem=0 if IMD1004=="IRL_2002"
replace cons_dem=0 if IMD1004=="IRL_2007"
replace cons_dem=0 if IMD1004=="IRL_2011"
replace cons_dem=0 if IMD1004=="IRL_2016"
replace cons_dem=0 if IMD1004=="ISL_1999"
replace cons_dem=0 if IMD1004=="ISL_2003"
replace cons_dem=0 if IMD1004=="ISL_2007"
replace cons_dem=0 if IMD1004=="ISL_2009"
replace cons_dem=0 if IMD1004=="ISL_2013"
replace cons_dem=0 if IMD1004=="KOR_2000"
replace cons_dem=0 if IMD1004=="KOR_2004"
replace cons_dem=0 if IMD1004=="KOR_2008"
replace cons_dem=0 if IMD1004=="KOR_2016"
replace cons_dem=0 if IMD1004=="LTU_2016"
replace cons_dem=0 if IMD1004=="MEX_1997"
replace cons_dem=0 if IMD1004=="MEX_2000"
replace cons_dem=0 if IMD1004=="MEX_2003"
replace cons_dem=0 if IMD1004=="MEX_2006"
replace cons_dem=0 if IMD1004=="MEX_2009"
replace cons_dem=0 if IMD1004=="MEX_2012"
replace cons_dem=0 if IMD1004=="MEX_2015"
replace cons_dem=0 if IMD1004=="PER_2006"
replace cons_dem=0 if IMD1004=="PER_2011"
replace cons_dem=0 if IMD1004=="PER_2016"
replace cons_dem=0 if IMD1004=="PHL_2016"
replace cons_dem=0 if IMD1004=="RUS_1999"
replace cons_dem=0 if IMD1004=="NZL_1996"
replace cons_dem=0 if IMD1004=="NZL_2002"
replace cons_dem=0 if IMD1004=="NZL_2008"
replace cons_dem=0 if IMD1004=="NZL_2011"
replace cons_dem=0 if IMD1004=="NZL_2014"
replace cons_dem=0 if IMD1004=="NZL_2017"
replace cons_dem=0 if IMD1004=="PRT_2005"
replace cons_dem=0 if IMD1004=="PRT_2009"
replace cons_dem=0 if IMD1004=="PRT_2015"
replace cons_dem=0 if IMD1004=="TUR_2011"
replace cons_dem=0 if IMD1004=="TUR_2015"
replace cons_dem=0 if IMD1004=="TUR_2018"
replace cons_dem=0 if IMD1004=="UKR_1998"
replace cons_dem=0 if IMD1004=="USA_2004"
replace cons_dem=0 if IMD1004=="USA_2008"
replace cons_dem=0 if IMD1004=="USA_2012"
replace cons_dem=0 if IMD1004=="ZAF_2014"

*Unclear cases 
replace cons_dem=. if IMD1004=="KEN_2013"
replace cons_dem=. if IMD1004=="MNE_2012"
replace cons_dem=. if IMD1004=="MNE_2016"

gen maj_dem=.
replace maj_dem=1 if cons_dem==0
replace maj_dem=0 if cons_dem==1
label var maj_dem "Majoritarian vs. consensus democracy, Lijphart"


